Using an array inside a map = { [ ] } in Javascript -
it doesn't seem possible declare map that, there way it?
i want kind of functionality:
var map = {[]}; // doesn't compile map["first"] = [1,2,3]; map["second"][0] = 4; map["second"][1] = 5; console.log(map["first"][1]); // want print 2 here console.log(map["second"][1]); // should print 5
is there way map similar this?
your code work perfectly.
edit: add new array object, need add new array object:
map.second = [];
if you're not sure whether exists yet, can check:
if (!map[somekey]) map[somekey] = [];
Comments
Post a Comment