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
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
push the flatten array but sliced, using sliceconst 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);