3 ms·
JavaScript does. var arr = ["one", "two", "three"]; arr["2"] === "three"; // true
by agency 9y ago
JavaScript does.
var arr = ["one", "two", "three"];
arr["2"] === "three"; // true
- marcins 9y agoJavaScript object property keys are always strings, so technically it’s `arr[2]` that has the 2 coerced to a string.
- Legogris 9y agoActually, that is incorrect. Arrays are different in JavaScript. I don't have time to look up the exact reference, but to get an idea: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe... > Arrays cannot use strings as element indexes (as in an associative array) but must use integers. Setting or accessing via non-integers using bracket notation (or dot notation) will not set or retrieve an element from the array list itself, but will set or access a variable associated with that array's object property collection. The array's object properties and list of array elements are separate, and the array's traversal and mutation operations cannot be applied to these named properties.
- Zalastax 9y agoIt's true that object keys are strings, but the array and object situation of JavaScript is quite confusing. Arrays are indexed by numbers, but still accept string indices, leading to behavior like this: https://stackoverflow.com/q/9526860 https://stackoverflow.com/q/9526860