push data into an array with pair values
You could do like this:
var d = [];
d.push([label, value]);
Maybe you would be better of using an object,
So you could do
var d = {
"Label" : "Value"
};
And to add the value you could
d.label = "value";
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
var items = [[1,2],[3,4],[5,6]];
alert(items[0][0]);
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...
for(var i = 0 ; i < labelssize; i ++)
{
items[i][0] = labelhere;
}
for(var i = 0 ; i < labelssize; i ++)
{
items[i][1] = valuehere;
}
What you need is a an array of objects.
Imagine this sample XML:
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
</book>
</catalog>
Your data structure could be:
var catalog = array(
{
'id': 'bk101',
'author': 'Gambardella, Matthew',
'title': 'XML Developer\'s Guide',
'genre': 'Computer'
},
{
'id': 'bk102',
'author': 'Ralls, Kim',
'title': 'Midnight Rain',
'genre': 'fantasy'
}
);
Then, you can acces the data like an array. Sample operations:
Read value:
var genre = catalog[0]['genre'];
Add a new property:
catalog[1]['price'] = '15.50';
List all titles:
for (var i=0; i<catalog.length; i++) {
console.log(catalog[i]['title'];
}