我有一个要遍历的 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
当我期待一个对象返回时,上面会返回这个:
为什么它返回一个值,而不是一个对象?