how can I push data into an array in js if it’s type is likw this… d= [[label, value]]. At first I want to push the label data then the values….
I get the data from an xml file.
If I had only a simple array I used the simple variable.push sintax.
Will varialble[][0].push or variable[][1].push work
how can I push data into an array in js if it’s type is
Share
Maybe you would be better of using an object,
So you could do
And to add the value you could
This might be a more structured approach and easier to understand if your arrays become big. And if you build the JSON valid it’s easy to make a string and parse it back in.
Like
var stringD = JSON.stringify(d); var parseD = JSON.parse(stringD);UPDATE – ARRAY 2D
This is how you could declare it
And the alert is reading from it,
To add things to it you would say
items[0][0] = "Label" ; items[0][1] = "Value";If you want to do all the labels then all the values do…