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

69
Vistas
Extract numbers from a n-dimensional array in javascript

Input array: [1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10]
Output array: [1,2,3,4,5,6,7,8, 9, 10]

Is there a way to get the output array without using multiple loops?

almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can add an infinity argument to flat to get all the numbers from the many nested arrays.

const data = [1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10];
const out = data.flat(Infinity);
console.log(out);

almost 4 years ago · Santiago Trujillo Denunciar

0

console.log([1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10].flat(Infinity));

Use 'flat' method to flatten the array. Or you can also use underscore module method.

almost 4 years ago · Santiago Trujillo 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