What would be the best way to go about separating the key and values into two different arrays so that this -
var data = {"A Key": 34, "Another Key": 16, "Last Key": 10};
Would become this -
data1 = ["A Key", "Another Key", "Last Key"];
data2 = [34, 16, 10];
Thanks.
var data = {"A Key": 34, "Another Key": 16, "Last Key": 10};
var data1 = [],
data2 = [];
for (var property in data) {
if ( ! data.hasOwnProperty(property)) {
continue;
}
data1.push(property);
data2.push(data[property]);
}
data
does not have this property explicitly (i.e. not higher up the prototype chain), skip this iteration.jsFiddle.
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