convert 9×9 array into 9 (3×3) array in javascript?
i have written the code, but its not pushing the 3×3’s into separate array.
i want 9 3×3 arrays
let array =[[1, 2, 3, 4, 5, 6, 7, 8, 9],
[2, 3, 1, 5, 6, 4, 8, 9, 7],
[3, 1, 2, 6, 4, 5, 9, 7, 8],
[4, 5, 6, 7, 8, 9, 1, 2, 3],
[5, 6, 4, 8, 9, 7, 2, 3, 1],
[6, 4, 5, 9, 7, 8, 3, 1, 2],
[7, 8, 9, 1, 2, 3, 4, 5, 6],
[8, 9, 7, 2, 3, 1, 5, 6, 4],
[9, 7, 8, 3, 1, 2, 6, 4, 5]];
let final=[];
let row=[0,1,2];
let col=[0,1,2];
let counter=0;
for(let i=0;i<=array.length-1;i+=3)
{
for(let j=0;j<=array.length-1;j+=3)
{
final.push([]);
row.forEach(ele1=>{
final[counter].push([])
col.forEach(ele2=>{
final[counter][ele1].push(array[ele1+i][ele2+j]);
})
})
counter+=1;
}
}