Consider you have an object,
const author = { firstName: 'Param', lastName: 'Harrison', age: 31 };
You can convert the object key-value into a nested array using the entries
method,
console.log(Object.entries(author)); // [["firstName", "Param"], [...], [...]]
Using Object.entries
, you can easily iterate over the key-value pair,
for (const [key, value] of Object.entries(author)) { console.log(`${key}: ${value}`); }
You can play with the code example,