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

160
Views
How can I get all the object inside an object which is present inside an array and add the result into another array

I am struggling with an issue that is bugging me a lot. I am not good with JSON data manipulation.

So the issue is I have an Array of multiple Object which contain some data, Now inside these objects, I have another array of objects which I want

the JSON looks something like this-

const data = [{
  a: 2,
  b: 3,
  c: 4,
  d: [{
    e: 5,
    f: 4,
    g: 6,
  }, {
    h: 5,
    i: 4,
    j: 6,
  }]
}, {
  a: 11,
  b: 31,
  c: 42,
  d: [{
    e: 54,
    f: 46,
    g: 62,
  }, {
    h: 55,
    i: 42,
    j: 64,
  }]
}]

Now What I want is an Array which holds the following data

const d = [{
  e: 5,
  f: 4,
  g: 6,
}, {
  h: 5,
  i: 4,
  j: 6,
}, {
  e: 54,
  f: 46,
  g: 62,
}, {
  h: 55,
  i: 42,
  j: 64,
}]

I tried mapping over the data but I always end up with an array that look

const data = [
  [{
    e: 5,
    f: 4,
    g: 6,
  }, {
    h: 5,
    i: 4,
    j: 6,
  }],
  [{
    e: 54,
    f: 46,
    g: 62,
  }, {
    h: 55,
    i: 42,
    j: 64,
  }]

]

Not sure what am i doing wrong. need some help

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

0

You can loop over the data and then loop over the data.d again to get all of the required data. For each of the data, you push it into another array that you will later use.

const data = [{a:2,b:3,c:4,d:[{e:5,f:4,g:6,},{h:5,i:4,j:6,}]},{a:11,b:31,c:42,d:[{e:54,f:46,g:62,},{h:55,i:42,j:64,}]}]
let result = [];
data.forEach(d => d.d.forEach(dd => result.push(dd)));
console.log(result);

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!