I understand that there are no associative arrays in JavaScript, only objects.
However I can create an array with string keys using bracket
Well, you are creating an array, which is in fact an object:
var arr = [];
arr.map;
// function(..)
arr['map'];
// function(..)
arr['a'] = 5;
console.log(arr instanceof Object); // true
You can add fields and functions to arr
. It does not "insert" them into the array though (like arr.push(...)
).
You can refer to an object fields with the []
syntax.