Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

101
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda