Re:Why perl has separate arrays and hashes: It's as if they ...
by __david__ on Tuesday June 21, 2011 @02:58PM
(#2679939)
> I'm not sure if I'd characterize Javascript's handling of arrays and hashes as conflated.
Insomuch as [] and {} produce arrays and object, yes, you are correct. But those objects are strikingly similar and the functions in each prototype work on the other. To the outside observer, only the length bit works differently.
I can do:
a = new Array();
a["b"] = 1;
for (x in a) { /* x will be "b" here*/ }
a.length /* 0 */
and d = {0:"a",1:"b",2:"c",3:"d",length:4}
Array.prototype.slice.call(d, 1,3) /* returns ["b", "c"] */
That's conflated a little bit.
To answer your question I don't know of many languages which conflate the two. I know a lot of languages which offer similar methods, to create parity between arrays and hashes (since they are similar enough data structures) but not many which treat them the same.