I need to convert JSON object string to a JavaScript array.
This my JSON object:
{"2013-01-21":1,"2013-01-22":7}
And I want to have:
var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
['2013-01-21', 1],
['2013-01-22', 7]
]);
How can I achieve this?
You can insert object items to an array as this
Suppose you have:
You could get the values with:
Output:
As simple as this !
See this complete explanation: http://book.mixu.net/node/ch5.html
http://jsfiddle.net/MV5rj/
This will solve the problem:
Or using Object.entries() method:
In both the cases, output will be: