Back
I want to convert an object that looks like this:
{"1":72,"2":12,"2":91};
into an array of key-value pairs like this:
[[1,72],[2,12],[2,91]].
How can I convert an Object to an Array of key-value pairs in JavaScript?
To convert an object to an array of key-value pairs in javascript, you can use Object.keys() and map() to do it. For example:
Var object={“1”:72,”2”:12,”3”:91};Var result=Object.keys(object).map((key)=>[Number(key),object[key]);console.log(result);
Var object={“1”:72,”2”:12,”3”:91};
Var result=Object.keys(object).map((key)=>[Number(key),object[key]);
console.log(result);
Want to be a Web Developer? Check out web developer certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users