[英]Get value of object inside of array which is inside an object itself
I have a quick question which I seem to be tripped up on.我有一个简短的问题,我似乎被绊倒了。
I have a data structure like so:我有一个像这样的数据结构:
data: {
accounts: [{
info: false
}]
}
Is there a "fancy" React way for me to get the value of the boolean associated with the info
key?是否有一种“花哨的” React方式可以让我获取与
info
键关联的布尔值?
I can of course retrieve the value with using map
or find
, but it always ends up being somewhat convoluted or involved code.我当然可以使用
map
或find
检索值,但它最终总是有些复杂或涉及代码。
If I do something like如果我做类似的事情
const { accounts } = data;
const customer = accounts.map(a => a.info);
The value for customer
always ends up coming back as [false]
instead of just false
, which is really confusing me, because I am not sure why it would come back inside of an array, where it is not an array to begin with, and it is being mapped out of an array ( accounts
). customer
的值总是最终返回为[false]
而不仅仅是false
,这真的让我感到困惑,因为我不确定为什么它会返回到数组内部,它不是从数组开始的,并且它被映射出一个数组( accounts
)。
I had the same result when using forEach
and find
.使用
forEach
和find
时我得到了相同的结果。
Is there something I'm missing?有什么我想念的吗? There has to be a quick Reactive one-liner to get the boolean value I'm looking for, and set it to a variable.
必须有一个快速的反应式单行来获取我正在寻找的布尔值,并将其设置为一个变量。
Anyone...?任何人...?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.