[英]React native object in object
I have a state like this:我有这样的状态:
"answers": {
"1": {
"name": "....",
"order": "....",
"text": "...,
"type": "..."
},
"2": {
"name": "...",
"order": "...",
"text": "....",
"type": "..."
},}
I need only names.我只需要名字。 I tried this.state.answers[0][1] but it doesnt work.
我试过 this.state.answers[0][1] 但它不起作用。 how can ı select only names ?
我怎么能只选择名字?
Object.values(answers)
will gives you the values of the object as array. Object.values(answers)
将为您提供对象作为数组的值。
Object.values(ansers).map( a => a.name)
just take the names Object.values(ansers).map( a => a.name)
只取名字
Maybe learning JS basics, like Object and Array , could be better than skipping to jump into React.也许学习 JS 基础知识,比如Object和Array ,可能比跳到 React 更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.