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

223
Views
Multiple Arrays to Single Flatterned Array

Ive got 3 parent arrays that could sometimes be different lengths which are called Options Each Option has values array which can also be different lengths Example of this would be something like this

[
  {
    name: "Option 1",
    values: ["Blue","Red","Orange"]
  },
  {
    name: "Option 2",
    values: ["Small","Medium","Large"]
  },
  {
    name: "Option 3",
    values: ["Cotton","Satin"]
  }
]

The outcome should generate an array like this

[
  {
    title: "Blue/Small/Cotton",
    price: "10.00"
  },
  {
    title: "Blue/Small/Satin",
    price: "10.00"
  },
  {
    title: "Blue/Small/Cotton",
    price: "10.00"
  },
  {
    title: "Blue/Medium/Satin",
    price: "10.00"
  },
]

And So on. Ive tried mapping through the options but knowing the size of the multiple arrays is what I couldnt figure out

SOLUTION I managed to get a solution

product.options.reduce(
      (a, b) => a.flatMap((x) => b.values.map((y) => [...x, y])),
      [[]]
    );
about 4 years ago · Juan Pablo Isaza
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!