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

88
Views
How does one consolidate multi-dimensional arrays?

I am trying to get one array with a complete string:

['...']

Given:

Array1 = ['...', ['...'], ['...', 2, 'x']]

This should handle any size array*

Define a function, zooInventory, that accepts a multi-dimensional array of animal facts.

zooInventory should return a new, flat array. Each element in the new array should be a sentence about each of the animals in the zoo.

What I have currently:

const zooInventory = array => {
    let finalArray = [];
  for (let i = 0; i < array.length; i++) {
      let currentElement = array[i];
     if (!(Array.isArray(currentElement))) {
         finalArray.push(currentElement);
     } else {
         zooInventory(currentElement);
// I thought I could push the currentElement back to beginning to handle additional arrays 
     }
    }
  return finalArray;
}

Where my heads at:

I thought I could get away with having it push(...array) in the else statement.

My batman belt contains beginner methods... slice, splice, spread.

What method would be best practice?

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

0

Simply use the .flat() method as shown in the snippet below.

More information here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat

let arrayOne = ['...', ['...'], ['...', 2, 'x']];

console.log(arrayOne.flat());

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!