【发布时间】:2021-02-12 14:35:24
【问题描述】:
我正在尝试访问每个项目的每个列表对象的单独计数值,以在数组中使用它们。我尝试了各种地图方法,但它一直返回未定义。我需要一种动态方法来收集这些计数,以便在添加更多列表、项目、位置和计数时,它会更新。
数据:
const data = [
{
name: "List1",
items: [
{
name: "Item1",
locations: [
{ position: "a", count: 20 },
{ position: "b", count: 30 },
],
},
{
name: "Item2",
locations: [
{ position: "c", count: 40 },
{ position: "d", count: 50 },
],
},
],
},
{
name: "List2",
items: [
{
name: "Item3",
locations: [
{ position: "e", count: 60 },
{ position: "f", count: 70 },
],
},
{
name: "Item4",
locations: [
{ position: "g", count: 80 },
{ position: "h", count: 90 },
],
},
],
},
];
期望的结果:
const onlyCounts = [20,30,40,50,60,70,80,90];
任何提示或信息将不胜感激,谢谢!
【问题讨论】:
-
“我尝试过各种地图方法”...比如?
标签: javascript arrays reactjs object array.prototype.map