> My complaint is that PHP's only first-class array type is a weird array/map combo. Have you ever seen anything like that in another language?
Um, Javascript?
Um, Javascript?
--
Clarification edit: Creating a new key on an array using arr['key']=1 creates a property on the arr Object but does not add an element to the standard array.
http://stackoverflow.com/questions/8630471/strings-as-keys-o...
var x = [];
console.log(Object.prototype.toString.call(x));
//[object Array]
x[0] = 1;
console.log(x[0]);
//1
x["test"] = 2;
console.log(x["test"]);
//2
console.log(Object.prototype.toString.call(x));
//[object Array]
x.map
//function map() { [native code] }
var y = {};
console.log(Object.prototype.toString.call(y));
//[object Object]
y.map
//undefined x = [1]; x["test"] = 555; x.map(function (y) { return y; });
// [1]
That's [1], not [1, 555]. You can access the array from the map interface, but not the other way around. var x = {};
x[0] = 1;
x.length = 1;
x.map = Array.prototype.map;
x.map(function(y) {return y;});
//[1]That is the whole reason prototype.js library broke the use of for (var x in somearray) because the library set properties on Array.prototype.
Array are objects,but all objects aren't Arrays.
var a={};
a instanceof Array // false
Furthermore,Javascript objects aren't maps.