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

135
Views
Combine Nested Array in ES6

I need to combine and display the validationMessages. How do it combine since they are nested?

const errors = [
    {
        "id": "101_1.jpeg",
        "imageValidationMessages": [
            {
                "attribute": "test",
                "validationMessages": [
                    "Error message 1"
                ]
            }
        ]
    }
]


  const errorMessages =
    errors?.length &&
    errors?.imageValidationMessages?.flatMap(
      (o) => o.validationMessages
    )
    
    
    console.log(errorMessages)

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

0

You can do something like this

 const errorMessages =
 errors?.length &&
 errors?.flatMap((err => err.imageValidationMessages?.flatMap(
  (o) => o.validationMessages
 )))
about 4 years ago · Juan Pablo Isaza Report

0

const errors = [
    {
        "id": "101_1.jpeg",
        "imageValidationMessages": [
            {
                "attribute": "test",
                "validationMessages": [
                    "Error message 1"
                ]
            }
        ]
    }
]
let arr=errors.map(e=>e.imageValidationMessages.map(p=>p.validationMessages)).flat(2)
console.log(arr)


const errors = [
    {
        "id": "101_1.jpeg",
        "imageValidationMessages": [
            {
                "attribute": "test",
                "validationMessages": [
                    "Error message 1"
                ]
            }
        ]
    }
]
let arr=errors.flatMap(e=>e.imageValidationMessages.flatMap(p=>p.validationMessages))
console.log(arr)

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!