题解 | #属性遍历#
属性遍历
https://www.nowcoder.com/practice/0158a4f165154f2eaf27d1907aa55e57
方法1
function iterate(obj) {
let arr=[]
for(let key in obj){
if(obj.hasOwnProperty(key)){
arr.push(key.concat(': ',obj[key]))
}
}return arr
}
方法2
function iterate(obj) {
let arr=[]
Object.keys(obj).forEach(key=>{
arr.push(key+': '+obj[key])
})
return arr
}
查看21道真题和解析