如何在对象中的数组中获取嵌套数组中的数据

桑斯卡·萨胡

我需要在 Data 数组中获取一些数据

我也使用新的 Array 类型的东西,但不是如何获得的东西

const Data = [
      {
        title: "About me",
        subtitle: "for more details",
        description:
          "Lorem, ipsum dolor sit amet consectetur adipisicing elit.",
  },

  {
    progressBar_forntend: [
      {
        progress_title: "html",
        width: "85%",
      },
      {
        progress_title: "css",
        width: "72%",
      },
    ],
  },
];

我想要这种类型的数据

Data.map((e)=>{
console.log(e.progressBar_forntend.progress_title)
})

但不工作

我需要使用map方法获取数据

克华尔

您最外面的数组有两个对象,一个没有,一个有“progressBar_forntend”。因此,我首先过滤具有“progressBar_forntend”的对象。其次,“progressBar_forntend”本身就是一个数组。最后我flat()用来展平嵌套的标题数组。

const Data = [{
    title: "About me",
    subtitle: "for more details",
    description: "Lorem, ipsum dolor sit amet consectetur adipisicing elit.",
  },
  {
    progressBar_forntend: [{
        progress_title: "html",
        width: "85%",
      },
      {
        progress_title: "css",
        width: "72%",
      }
    ]
  }
];


let filtered = Data.filter(dataitem =>
  Object.keys(dataitem).includes('progressBar_forntend'));

result = filtered.map(item =>
  item.progressBar_forntend.map(item => item.progress_title));

result = result.flat();

console.log(result);

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在对象数组的嵌套数组中获取数组对象javascript

如何从数组对象中的嵌套数组获取数据

在对象的嵌套数组中过滤

如何从嵌套数组中获取数据

如何在对象的嵌套数组中添加对象而不改变原始源

如何在对象嵌套数组中填充对象值?

使用Formik.js时如何在对象中创建嵌套数组?

在对象的嵌套数组中查找数组

如何在嵌套数组中过滤JSON对象数组

如何在React Native中获取数组对象内的嵌套数组对象

如何渲染属性嵌套在对象嵌套数组中的元素数组?

如何在MongoDB中更新嵌套数组中的数据

检查嵌套数组中是否存在对象 reactjs

Ansible - 在对象列表中循环嵌套数组?

在对象的嵌套数组中搜索js

在对象javascript express中过滤嵌套数组

如何从带有对象的嵌套数组中获取值

如何从 MongoDB 嵌套数组中获取对象

在JavaScript中执行计算后,如何在嵌套数组中获取所有对象?

如何在 React-Native 的屏幕上访问嵌套数组 JSON 数据中的嵌套对象

在 javascript 中,如何从 json 数据创建嵌套数组或对象?

MongoDB:如何在嵌套数组中插入对象?

如何在mongodb中查询对象的嵌套数组?

如何在 React 中访问嵌套数组对象

如何通过php从嵌套数组中获取API数据

如何从嵌套数组中获取数据[Laravel]

如何在对象中获取数组对象

如何在Javascript中获取嵌套数组的长度?

如何在嵌套数组中获取项目