Object.keys和Object.values和Object.entries

 let obj = {
        name:'terry',
        age:12,
        gender:'male'
}
var keys = Object.keys(obj);  //打印出来的是值 name,age,gender
var values= Object.values(obj);  //打印出来的是值 terry,12,male
var entries= Object.entries(obj);  //打印出来的是值 ['name':'terry'],['age':'12'],['gender':'male']
 for(let[key,value] of keys){
     console.log(key);//name   age  gender
     console.log(value);//  terry,12,male
  }
  for(var key in obj){
      console.log(key);//name   age  gender
      console.log(obj[key])//  terry,12,male
  }

你可能感兴趣的:(ES6)