Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

148
Views
how to map through a property inside an array of arrays of objects - reactjs

how can I map through a property inside an array of arrays of objects?

to clarify my point here is my code structure, outer array that contains 4 inner arrays - the number shouldn't be four - each inner array has a property title which I want to pick. I want to pick all the tiltle properties inside inner array and get it back in a separate array

Array(4)
0: Array(1)
0: {_id: 'Mc-mi_000000001', title: 'McRoyale', section: {…}, imageSrc: 'McRoyal.png', price: 70, …}
length: 1
[[Prototype]]: Array(0)
1: Array(2)
0: {_id: 'Mc-mi_000000002', title: 'Big Mac', section: {…}, imageSrc: 'Bigmac.png', price: 55, …}
1: {_id: 'Mc-mi_000000003', title: 'Big Tasty', section: {…}, imageSrc: 'Big-tasty-Beef.png', price: 75, …}
length: 2
[[Prototype]]: Array(0)
2: Array(3)
0: {_id: 'Mc-mi_000000022', title: 'McNuggets 6 Pieces', section: {…}, imageSrc: 'McNuggets-6psc.png', price: 50, …}
1: {_id: 'Mc-mi_000000030', title: 'McFries', section: {…}, imageSrc: 'Large-Frise.png', price: 30, …}
2: {_id: 'Mc-mi_000000039', title: 'American Coffee', section: {…}, imageSrc: 'Ame-R-700x474.png', price: 25, …}
length: 3
[[Prototype]]: Array(0)
3: Array(1)
0: {_id: 'Mc-mi_000000041', title: 'Happy Meal Cheeseburger', section: {…}, imageSrc: 'HM-D-Chesseburger.png', price: 35, …}
length: 1
[[Prototype]]: Array(0)
length: 4
[[Prototype]]: Array(0)

how can I put the title property in each inner array into a separate array?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

If you want to keep the nested array structure you can use a map function on the inner arrays inside the map function of the outer/main array.

const data = [
  [
    {_id: 'Mc-mi_000000001', title: 'McRoyale'}
  ], [
    {_id: 'Mc-mi_000000002', title: 'Big Mac'},
    {_id: 'Mc-mi_000000003', title: 'Big Tasty'}
  ], [
    {_id: 'Mc-mi_000000022', title: 'McNuggets 6 Pieces'},
    {_id: 'Mc-mi_000000030', title: 'McFries'},
    {_id: 'Mc-mi_000000039', title: 'American Coffee'}
   ]
];

const titleData = data.map(innerArray => innerArray.map(({title}) => title));

console.log(titleData);

/*Expected results:
  [
    [
      "McRoyale"
    ],
    [
      "Big Mac",
      "Big Tasty"
    ],
    [
      "McNuggets 6 Pieces",
      "McFries",
      "American Coffee"
    ]
  ]
*/

about 4 years ago · Juan Pablo Isaza Report

0

You can collect those titles by calling .map nested:

const data = [[{_id: 'Mc-mi_000000001', title: 'McRoyale' }], [{_id: 'Mc-mi_000000002', title: 'Big Mac'},{_id: 'Mc-mi_000000003', title: 'Big Tasty'}], [{_id: 'Mc-mi_000000022', title: 'McNuggets 6 Pieces' },{_id: 'Mc-mi_000000030', title: 'McFries' },{_id: 'Mc-mi_000000039', title: 'American Coffee'}], [{_id: 'Mc-mi_000000041', title: 'Happy Meal Cheeseburger' }]];

const titles = data.map(arr => arr.map(({title}) => title));
console.log(titles);

about 4 years ago · Juan Pablo Isaza Report

0

One possibility is first to flatten your arrays into one then go through it with a map:

[[{title: "a"}, {title: "b"}], [{title: "c"}]].reduce((acc, arr) => ([...acc, ...arr]), []).map(obj => obj.title)
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!