[英]How to extract data value that is nested inside an array
I am just trying to figure out why when trying to grab a value through the dot notation, it is giving me undefined error.我只是想弄清楚为什么在尝试通过点表示法获取值时,它会给我未定义的错误。 Please see below for what I mean.
请看下面我的意思。
I am trying to extract the value from the nested object in the headline color array:我正在尝试从标题颜色数组中的嵌套对象中提取值:
If we can assume that el.selectgroup1
is equal to some string value "[{name: 'Off White', value: 'off-white'}]"
.如果我们可以假设
el.selectgroup1
等于某个字符串值"[{name: 'Off White', value: 'off-white'}]"
。 then we can deduce that el.selectgroup1[0]
is equal to "["
.那么我们可以推断出
el.selectgroup1[0]
等于"["
。 which would not be valid JSON within JSON.parse("[")
.这在
JSON.parse("[")
中不是有效的 JSON。
Try something like JSON.parse(el.selectgroup1)[0].value
尝试像
JSON.parse(el.selectgroup1)[0].value
这样的东西
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.