Object.entries() of the Object constructor method

Object.entries() of the Object constructor method

Object.entries( obj )

Returns an array of key-value pairs of the enumerable properties of a given object itself, the arrangement of which is the same as the return order when using the for...in loop to traverse the object (the difference is that the for...in loop also enumerates the properties in the prototype chain)

Generally speaking, Object.entries() can traverse the key value of an object in the form of an array, the order is the same as for...in, but it will not traverse the prototype property

 

description

Object.entries() returns an array whose elements are the arrays corresponding to the enumerable property key-value pairs found directly on the object. The order of the attributes is the same as the order given by manually cycling through the attribute values ​​of the object.

Javascript Demo: Object.entries()

const obj = {
  A:'hy',
  B:12
};
console.log(Object.entries(obj)) // [[‘A’,'hy'],[‘B',12]]

for(let [key, value] of Object.entries(obj)){
     console.log(`${key}:${value}`) // A:hy  B:12
}

Guess you like

Origin blog.csdn.net/weixin_43844696/article/details/108405030