Object.entries()

Object.entries() can be used to convert an object into a key/value pair in the form of an array. That means your object will be converted into a 2D array (at the simplest level), with each element being another array containing a key and value. Take a look at this:

const obj = {    book: "Learning ES2017 (ES8)",    author: "Mehul Mohan",    publisher: "Packt",    useful: true};console.log(Object.entries(obj));

The output will be:

[["book","Learning ES2017 (ES8)"],["author","Mehul Mohan"],["publisher","Packt"],["useful",true]]

Get Learn ECMAScript - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.