📅  最后修改于: 2020-10-25 11:05:20             🧑  作者: Mango
JavaScript Object.entries()方法用于返回给定对象自己的可枚举属性[key,value]对的数组。属性的顺序与手动遍历对象的属性值所给出的顺序相同。
Object.entries(obj)
对象:这是一个要返回其可枚举属性[key,value]对的对象。
此方法返回给定对象自己的可枚举属性[key,value]对的数组。
Chrome | 38 |
Edge | Yes |
Firefox | 28 |
Opera | No |
const obj = { 10: 'arry', 21: 'barry', 23: 'carry' };
console.log(Object.entries(obj)[2]);
输出:
["23", "carry"]
// creating an object constructor.
// and assigning values to it.
const obj = { 1: 'marrc', 2: 'sort', 3: 'carry' };
// Displaying the countable property [key, value]
// pairs of the object using object.entries() method.
console.log(Object.entries(obj)[2]);//access obj.
输出:
["3", "carry"]
// creating an object constructor.
// and assigning values to it.
const obj2 = { 10: 'arvind', 2: 'rahul', 7: 'Ankit' };
// Displaying the countable property [key, value]
// pairs of the object using object.entries() method.
console.log(Object.entries(obj2)[2]);
输出:
["10", "arvind"]