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

90
Views
ForEach inside Foreach Javascript

Hi how do I loop trough an array i already looped trough? So i foreach the subarray and still having the the old array

array =  [
{
"DocNum": 210446, 
"DocType": "Test",
"DocumentLines": [
{
"LineNum": 0,
"ItemCode": "427"
}, 
{
"LineNum": 0,
"ItemCode": "34"
}
]
},
{
"DocNum": 210446, 
"DocType": "Test",
 "DocumentLines": [
{
  "LineNum": 0,
  "ItemCode": "427"
  }, 
  {
    "LineNum": 0,
    "ItemCode": "34"
    }
  ]
  }
 ]

for (let element of array) {
 newArray.push({
    key1: element.DocNum,
    key2: element.DocType,
    key3: element.DocumentLines[???].ItemCode
})}

So the array will look like this in the end

{ "key1":210446, "key2":Test, "key3": [{ItemCode: 34},{"ItemCode": 427}] }

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

0

You can map the itemCodes

element.DocumentLines.map(v => v.ItemCode)

This will return the array of ItemCodes from your first array.

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!