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 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