遍历对象属性:
1.用for...in...遍历
let person = {
name: 'henry',
age: 18,
}
for (let key in person) {
console.log('键名:' + key + ';键值:' + person[key]);
}
2.借助Object.keys遍历
let person = {
name: 'henry',
age: 18,
}
let keys = Object.keys(person);
for (let i = 0; i < keys.length; i++) {
console.log('键名:' + keys[i] + ';键值:' + person[keys[i]]);
}
标签:遍历,person,对象,keys,let,key,键值,属性
From: https://www.cnblogs.com/ppch-max/p/16837584.html