I am new to Javascript. I have a Javascript object like so:
s = {"Toothless":"Dragon","Foo":"Bar"};
I need to convert it into a series of arrays, like so:
out = [["Toothless","Dragon"],["Foo","Bar"]];
This is the reverse of what is discussed in Convert JavaScript array of 2 element arrays into object key value pairs. A JQuery solution is acceptable.
You can map over the items to achieve this:
s = {"Toothless":"Dragon","Foo":"Bar"};
var out = Object.keys(s).map(function(data){
return [data,s[data]];
});
console.log(out);
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