Object.entries()

Temitope Ayodele - May 9 '20 - - Dev Community

Object.entries() is used for listing all key-value pairs in an object. It accepts an object as a argument, and returns an array enumerating the key-value pairs of an object.

const obj = { 
  1: 'Israel', 
  2: 'Temi', 
  3: 'Miro' 
};
console.log(Object.entries(obj))

//Expected result: [ ["1", "Israel"], ["2", "Temi"], ["3", "Ayo"]]
Enter fullscreen mode Exit fullscreen mode

Another example:

const obj1 = {
  a: 'Hello',
  b: 28
};

for (let [key, value] of Object.entries(obj1)) {
  console.log(`${key}: ${value}`);
}

//Expected result: 
// "a: Hello"
// "b: 28"
Enter fullscreen mode Exit fullscreen mode

If the argument passed is not an object, it causes TypeError,
If the key passed in the argument is not in the range of the property[key, value] pair, it causes RangeError.

. . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player