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)
上一篇:《java.util.concurrent 包源码阅读》03 锁


下一篇:前端必备的网址汇总