es8对object快速遍历的方法
作者:互联网
let grade = { 'lilei' : 96, 'han' : 99 } //遍历keys console.log(Object.keys(grade)) console.log(Object.keys(grade).filter(item => item === 'lilei')) //遍历values console.log(Object.values(grade)) console.log(Object.values(grade).filter(item => item > 96)) //object.entries:把对象变成可遍历的对象 let result = [] for (let [k, v] of Object.entries(grade)) { console.log(k, v) if(k === 'lilei') { result.push(k) } } console.log(result)
标签:遍历,console,log,item,grade,object,es8,Object 来源: https://www.cnblogs.com/qjb2404/p/12231331.html