Home > Software engineering >  how to get data in nesting array in object in array in object
how to get data in nesting array in object in array in object

Time:10-03

I want need to get some data in the Data array

I also using new Array type things but not things how to get

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%",
      },
    ],
  },
];

I want this type of data

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

but is not work

I need to get data by using the map method

CodePudding user response:

Your outermost array has two objects, one without and one with "progressBar_forntend". So, I filter first for the objects that has "progressBar_forntend". Second, "progressBar_forntend" is itself an array. Finally I use flat() to flatten the nested array of titles.

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);

  • Related