Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

89
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda