DEV Community 👩‍💻👨‍💻

Max Angelo Dapitilla Perin
Max Angelo Dapitilla Perin

Posted on

Answer: How to convert an Object {} to an Array [] of key-value pairs in JavaScript

Yet another solution if Object.entries won't work for you.

const obj = {
      '1': 29,
      '2': 42
    };
const arr = Array.from(Object.keys(obj), k=>[`${k}`, obj[k]]);
console.log(arr);

Top comments (0)

Let's Get Wacky


Use any Linode offering to create something unique or silly in the DEV x Linode Hackathon 2022 and win the Wacky Wildcard category

Join the Hackathon <-