Linked Questions

1 vote
1 answer
208 views

I have had discussions with seasoned programmers who do not think arrays are objects; they think that objects and arrays are of separate types of the data structure category. But, as far as I ...
Custer's user avatar
  • 117
1 vote
1 answer
251 views

I played around with the Object.assign function and found out that i can create an array object fusion kinda? the code looks like this: var list = [1, 2, 3] Object.assign(list, {property: true}) the ...
Atilla's user avatar
  • 41
0 votes
1 answer
81 views

I am aware that everything is an object in JavaScript but something struck me when i was using the console of Internet Explorer -F12 (Yes IE, not allowed to use other browsers) If i type a sample ...
krishna's user avatar
  • 595
-4 votes
2 answers
181 views

I'm looking for an elegant way of understanding JavaScript array and objects. I came to an anomaly in which I got stuck. Since in PHP or other languages, when we make an array e.g $a = [ admin =&...
Saddam's user avatar
  • 1,206
2 votes
1 answer
106 views

A colleague, by mistake wrote this code: var parameters = []; // some lengthy code here parameters.firstParameter = "first parameter value"; parameters.secondParameter = "second parameter value"; He ...
1 vote
0 answers
58 views

A strange behavior of array assignment at index: array[<some string>]. Let's say I have a normal array: const arr = [1, 2, 3]; // undefined If I type: arr['.'] = 4; // 4 arr // (3) [1, 2, 3, .:...
MaxG's user avatar
  • 1,077
0 votes
0 answers
41 views

I was stumbling around in JavaScript and was wondering why my tests were still working, although I changed a constant from an Object to a Variable. I'm aware that Object properties can be accessed by ...
0 votes
0 answers
31 views

Why do javascript arrays allow me to use a string as a key index? For example, let r = []; r['test'] = 'testvalue' // [testvalue: 321] Arrays can be used like objects. Is that because everything in ...
0 votes
0 answers
29 views

Today i'm facing a really strange behavior, check this out ! const person = []; person.name = "Hello World" console.log(person) // [name: "Hello World"] That is crazy, I just pushed some key - value ...
J.doe's user avatar
  • 185
1037 votes
77 answers
987k views

A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java? Stack Overflow question Is ...
user avatar
11 votes
4 answers
16k views

I recently learned about optional chaining in Javascript and have been making use of it in a React/NodeJS project. Works great. I noticed I have been using it with arrays map, even without thinking ...
3 votes
3 answers
13k views

So I was reading an article to clone an object and array. All of them mentioned that Object.assign() can be used to copy an object but no one mentioned that Object.assign() will also work to shallow ...
2 votes
4 answers
14k views

I definitely need some light on this. What's the diference between: var MY_APP = function(){ this.firstMethod = function(){ //something }; this.secondMethod = function(){ //...
1 vote
5 answers
1k views

I am trying to understand something in JavaScript. Lets say I do the following: let x = []; x['Monday'] = 'Work'; x['Tuesday'] = 'More Work'; console.log(x) //[Monday: "Work", Tuesday:...
2 votes
2 answers
2k views

I want to change only one element of a multidimensional array // nodes is a 2-dimensional array // of 30 rows and 30 columns this.state = {nodes}; // updatedNodes is a deep copy of nodes ...
1 vote
3 answers
2k views

TypeScript function chaining, but I want to programmatically chain them. Example class: chain.ts class MyChain { value: number = 0; constructor() { this.value = 0; } sum(args: number[]) { ...
Dan7el's user avatar
  • 2,077
2 votes
1 answer
1k views

While I don't know the name of this functionality: a = [] a[57] = "test"; console.log(a.length) console.log(a[57]) console.log(a) I am in awe that this is possible. Coming from a C ...
toobulkeh's user avatar
  • 1,616
0 votes
2 answers
729 views

Hi I am attaching a screenshot of my Firefox Console and would like to know why does array behave like this in javascript. I was trying to understand for...in and for...of in js but came across this ...
shinite's user avatar
  • 2,116
-2 votes
2 answers
2k views

I discovered a bug on a project I'm working on that can be replicated by this snippet: const original = [ { value: 1 } ]; function test() { const copy = Object.assign([], original); copy....
Khryus's user avatar
  • 337
0 votes
2 answers
914 views

I faced a strange situation when I tried to create an array of arrays via fill and then I tried to add some value to the first child I saw all other nested arrays receive this value as well. I have an ...
Velidan's user avatar
  • 6,174
2 votes
1 answer
743 views

Last night I was sending some data to my server via AJAX (specifically, $.post), when I ran into the issue that JavaScript Arrays needed to be "stringified" and applied as a field to an object before ...
2 votes
2 answers
549 views

In the fiddle - http://jsfiddle.net/vwwkf18c/ or below code snippet - var a = [3, 4]; var b = [6, 2]; var c = $.extend({}, a, b); alert(c[1]); //alerts 2 alert(a); //alerts array a contents alert(c);...
-1 votes
4 answers
70 views

This function works fine but I don't want it to return the values, but the keys: const search = [2342,1900,1800,2310] search = search.filter(function (el) { return el > 2200; }); So it should ...
Hasen's user avatar
  • 12.5k
-1 votes
1 answer
216 views

I'm not able to get the value by dynamic key in following code, const data = { "Id": "1234", "status": "open", "Translations": ...
Aamir's user avatar
  • 2,293
1 vote
1 answer
378 views

i have a type ImageType and incoming props from parent, it can be an Object or Array of Objects. I'm cheking if prop is Object then get directly access the "src" property but as you can see ...
mirik999's user avatar
  • 389
1 vote
2 answers
103 views

In JavaScript, it is possible to loop through an object using the Object.keys method. With this, I can loop the person Object as: let person: { name: "John", lastName: "Doe", age: ...
1 vote
3 answers
85 views

I'm learning Javascript and would like to understand why indexOf isn't finding the array within the searched array. (An explanation, theory etc. is the goal for this one, no alternative code or other ...
-2 votes
1 answer
85 views

I want to have an array that elements inside look like this: Array(3) 0: name: true; 1: price : false; 2: stock: true; length: 3 So when I need to get any element, I could get it by calling property ...
Cavid's user avatar
  • 133
-1 votes
4 answers
97 views

Could someone explain this block of code to me and what the type of 'arr' is. I know that an array is an object but Why does the [[Class]] show up as Array if it behaves like an Object arr.length ...
var x's user avatar
  • 135
1 vote
0 answers
58 views

I'm working on PHP and trying to pass a PHP array to a javascript code to create an attribute dynamically and set the values to it. I've been sending the PHP array like below. PHP Code $dataArray = ...
Aravind's user avatar
  • 424
0 votes
0 answers
64 views

In the Javascript code: var people = [{name:"john",age:20},{name:"bob",age:30},{name:"kate",age:40}]; people.forEach(function(person,i){ person.isHuman = true; }) console.log(people) would give [{...