直接上代码
let myObj={ name:"喵喵喵", password:"123456", age:8 }; Object.keys(myObj).forEach(key => { console.log(key); });
输出
name
password
age
如果要取值的话,也是可以这样
let myObj={ name:"喵喵喵", password:"123456", age:8 }; Object.keys(myObj).forEach(key => { let currVal= myObj[key]; console.log("key是:", key, "value是:", currVal); });

微信扫码查看本文
发表评论