I have a JSON file that I would like to create an array from.
Here is the JSON data.
{
"table": {
"columnNames": ["column1", "column2", "column3", "column4"],
"columnTypes": ["String", "String", "String", "String"],
"rows": [
["data00", "data01", "data02", "data03"],
["data10", "data11", "data12", "data13"],
["data20", "data21", "data22", "data23"],
["data30", "data31", "data32", "data33"]
]
}
}
I need to create an array from the objects in the "rows" section.
Any help would be appreciated!
Thanks!!!
EDIT
Would it be possible to create a hash table out of the data in rows? Also, how would you perform JSON.parse on a json file? Thanks
Do you mean you want to get a single array holding all the values?
var rows = [];
for (var i = 0; i < data.table.rows.length; i++) {
rows.push.apply(rows, data.table.rows[i]);
}
See MDN docs for push
and apply
.
This assumes that you've stored the data from your question in a variable data
. If you only have it as a JSON string, you'll need to convert it with JSON.parse
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With