我有一个JSON对象,我想遍历它。
"phone": {
"Samsung": {
"type": "S7"
},
"iPhone": {
"type": "6S"
},
"Google": {
"type": "Pixel"
}
}
我正在使用 Object.key
来遍历这些值,我认为这是处理对象的正确方式:
render() {
//this.props.phone contains the objects "Samsung", "iPhone", and "Google"
return (
Object.keys(this.props.phones).map((type) => {
console.log(type)
return (
<p>Type of phone: {type}</p>
)
})
)
}
然而,我期望返回一个对象,但上面的 console.log
返回了这个值:
为什么它返回一个值而不是一个对象?