1、使用Object.keys()遍历
const str={"name":"duxin","num":"253","index":"958"} Object.keys(str).forEach((key)=>{console.log(key)})
2、for..in遍历
for(let i in str){ console.log(i+"===="+str[i]) }
3、Object.getOwnPropertyNames(obj)
Object.getOwnPropertyNames(str).forEach((key)=>{ console.log(key+"===="+str[key]) })
4、Reflect.ownKeys(obj)
Reflect.ownKeys(str).forEach((key)=>{ console.log("对象索引为:"+key) })
文章评论