I got a structure like this:
var Array = new Array(3);
Array["123"] = ["a","b","c"];
Array["456"] = ["d","e","f"];
Array["789"] = ["g","h","i"];
for example, how do I get "b"
var a = new Array();
a["123"] = ["a","b","c"];
a["456"] = ["d","e","f"];
a["789"] = ["g","h","i"];
b = a["123"][1];
sample :) http://jsbin.com/agolef/1/edit
[] instead of new Array() above, for the benefit of newbies reading these posts. (stackoverflow.com/questions/885156/…)a as an object by adding named properties instead of numeric indices (which is a misuse of an Array type object). For example, checking a.length would yield 0, which could be unexpected for a new user. All array indices are named properties, but not all named properties are array indices..length would not be 0. It would be 790.a["123"][1]; // yields "b"
a[123][1]; // also yields "b"
Indexing an array with a string is probably not what you meant to do.
var a = new Array(3);
a["123"] = ["a","b","c"]; // "123" causes the array to expand to [0..123]
a["123"][1]; // yields "b"
a[123] = ["a","b","c"]; // this has better performance and is idiomatic javascript.
a[123][1]; // also yields "b"
a["456"] = ["d","e","f"];
a["789"] = ["g","h","i"];
If you want to use an object as a map instead, try this:
a = new object()
a["123"] = ["a","b","c"];
a["123"][1]; // yields "b"
Array is a native constructor. Using a new object that doesn't add properties to the native object:
var obj = {};
obj["123"] = ["a","b","c"];
obj["456"] = ["d","e","f"];
obj["789"] = ["g","h","i"];
obj["123"][1]; // "123"
What your code was doing was adding a bunch of properties to the native Array, (which is a function object that makes array objects). For more on the difference between arrays and other objects, see this question
Array constructor. It was overwriting the constructor with an Array instance (assuming the code was run in the global scope).
array[123][1]- assuming you named yourvar array, don't use capitals for variable names.