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

144
Vistas
How to create array in array JS

It's my first steps in JS and I'm trying to solve one task I got but I have the mistake.

I create the array in array and change the value inside and when I use for loop it return the mistake:

My array

let arrOne= [[12,3], 431, 432, 3234,123,123,512,2];

arrOne[i]["0"]=13;
              ^

TypeError: Cannot create property '0' on number '0'

If you know how create array in array with "for" and put value there please help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

OP says:

I need to create array in array like that [[1,2,3],[4,5,6],[7,8,9]]

So with that in mind

  • You can flatten your array, so you can have all of your values in one array.
  • Then loop through the array by incrementing the loop index by 3.
  • Inside the loop you can push the flatten array but sliced, using slice

const arrayOne = [
  [12, 3], 431, 432, 3234, 123, 123, 512, 2
];
const arrayOneFlatten = arrayOne.flat();
const newArray = [];
const numberToGroup = 3

for (let index = 0; index < arrayOneFlatten.length; index += numberToGroup) {
  newArray.push(arrayOneFlatten.slice(index, index + numberToGroup));
}
console.log(newArray);

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