I want to make a structure like this:
var myThings = {
thing1: {
['24-04-12', '90'],
['25-04-12', '90'],
['26-04-12', '90']
},
thing2: {
['24-04-12', '10'],
['25-04-12', '30'],
['26-04-12', '210']
}
}
(There are 4 things, hardcoded).
The arrays in each object will be added in a loop, so my code looks like this:
var myThings = {"thing1":{}, "thing2":{}};
I then can’t work out how to push my arrays into the object.
Am I being dumb, or is this not the way to do this?
Thanks a lot!
You need to use an
Arrayinstead anObjectthere. LikeNow since
thing1andthing2areArraysyou can just useArray.prototype.pushto push newArraysinto thatArray.That code would add
['01-01-12', '42']to all currentthingsin that object.Disclaimer: The above code contains ES5. You need a browser which supports that or a Shim to emulate