#How do I access element in a nested array of objects ?

6 messages · Page 1 of 1 (latest)

muted plover
#

const data = [
{
name: "First",
First: [
{
title: "Leads",
icon: <Leads />,
},
{
title: "Deals",
icon: <Deals />,
},
{
title: "Projects",
icon: <Projects />,
},
{
title: "Campaigns",
icon: <Campaigns />,
},
],
},
{
name: "Second",
Second: [
{
title: "Mail",
icon: <Mail />,
},
{
title: "Activities",
icon: <Activities />,
},

  {
    title: "Contacts",
    icon: <Contacts />,
  },

  {
    title: "Insights",
    icon: <Insights />,
  },

  {
    title: "Products",
    icon: <Products />,
  },

  {
    title: "Marketplace",
    icon: <Marketplace />,
  },

  {
    title: "More",
    icon: <More />,
  },
],

},
];

#

I want to apply the filter method on the root to get the First array and then apply a function and then the second array and then apply a function

heady mirage
#

I'm unclear on what you're trying to accomplish. What do you mean by "apply the filter method on the root to get the First array"? If you call Array.filter() on the data array, that will return you a new array containing elements from the original array that meet some criteria, but you couldn't use it to get the First array. You would have to take a different approach.

#

Also, when you say "apply a function", do you mean you want to apply the same function to the First and Second arrays? 😕

muted plover
#

I simply want to access "First" array and "Second" array using map and filter

heady mirage
#

If all you want to do is simply access "First" array and "Second" array, this should get you that:

  const First = data[0].First;  // this is the "First" array
  const Second = data[1].Second;  // this is the "Second" array

Without having to use map or filter.