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.
You can loop through the properties with a
for in
loop, and then just assign them to arrays as needed.Make sure you check whether the key is a property of the object, and not of the prototype.
data
does not have this property explicitly (i.e. not higher up the prototype chain), skip this iteration.jsFiddle.
This function will split the
data
object into a keys and a values array. It returns an object, containing both arrays.