Create []array Dynamically In Javascript
Probably this will be a real stupid question to ask but im new in javascript and stuck with dynamic creation of array like in below format: items = [{ 'Date': '2012-01-21T23:45
Solution 1:
var items = []; // initialize array
items.push({ // add 1st item
"Date": "2012-01-21T23:45:10.280Z",
"Value": 7
});
items.push({ // add 2nd item
"Date": "2012-01-26T23:45:10.280Z",
"Value": 10
});
items.push({ // add 3rd item
"Date": "2012-05-30T23:45:10.280Z",
"Value": 16
});
And to view it:
console.log(JSON.stringify(items));
See:
- Javascript Array
Array.prototype.push
to add elememts
Solution 2:
Do you mean like this:
items = [];
items.push({
"Date": "2012-01-21T23:45:10.280Z",
"Value": 7
});
items.push({
"Date": "2012-01-26T23:45:10.280Z",
"Value": 10
});
items.push({
"Date": "2012-05-30T23:45:10.280Z",
"Value": 16
});
Post a Comment for "Create []array Dynamically In Javascript"