84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
When using the key name, an error is reported saying that the set property cannot be set
var o = { name: 'foo', hey: 'bar' } console.log(o.name); // => "foo" console.log(o['name']); // => "foo"
The above-mentioned ordinary js objects can only use strings as keys. es6 has a new feature that allows "value" to be used as the key. See example:
var m = new Map(); var eczn = { name: 'eczn', age: 20 } m.set(eczn, 'map Obj to Stirng'); console.log(m);
Arrays in JavaScript do not support using identifiers other than numbers as array subscripts, but you can use objects to achieve similar effects to associative arrays in PHP:
var myArray = {'key1': 'value1'}; console.log(myArray['key1']); // 会输出value1, 其实相当于myArray.key1
JS arrays use custom key names, which I have never used in development for so long. There is no need for it at all. Just use Object.
Yes, for example
var person = { "name" : "孤月" }; var n = "name"; console.log(person[n]); //设置键名 person[n] = "deep dark fantasy";
Original arrays cannot use characters other than numbers as key names. You can use objects as arrays to achieve the same functionality.
When defined, arrays can only be indexed by numbers, for example, while other types of index are objects. This is different from php.
JS does not have associative arrays, only basic arrays. What looks like associative arrays are objects. This js has them.
JS arrays can be subscripted with strings. Similar to associative arrays, the type of array subscript in JS is strings
JS Object
Map object
The above-mentioned ordinary js objects can only use strings as keys. es6 has a new feature that allows "value" to be used as the key. See example:
Arrays in JavaScript do not support using identifiers other than numbers as array subscripts, but you can use objects to achieve similar effects to associative arrays in PHP:
JS arrays use custom key names, which I have never used in development for so long. There is no need for it at all. Just use Object.
Yes, for example
Original arrays cannot use characters other than numbers as key names. You can use objects as arrays to achieve the same functionality.
When defined, arrays can only be indexed by numbers, for example, while other types of index are objects. This is different from php.
JS does not have associative arrays, only basic arrays. What looks like associative arrays are objects. This js has them.
JS arrays can be subscripted with strings. Similar to associative arrays, the type of array subscript in JS is strings