I need some help with my code. I try to insert only one value in each array. I need to fill in the row first and after that, if the row is full then move to the next column. I try to solve this part for a couple of days but I fail. So here is my code
const testData = [1,2,3,4,5,6,7,8,9];
const create2dArray = (row, column) => {
var result = [];
for(let i = 0; i< row; i++){
result[i]= [];
for(let j = 0; j<column; j++){
result[i][j] = [];
for(let e = 0; e < testData.length; e++){
result[i][j] = [testData[e]];
}
}
}
return result;
}
let Column = 5
let Row = 5
filterQuotaData(EnrollmentQuota);
var ground = create2dArray(Column,Row);
console.log(ground);
Suppose the output is :
[1],[2],[3],[4],[5]
[6],[7],[8],[9],[]
[],[],[],[],[]
[],[],[],[],[]
[],[],[],[],[]
instead, I got:
[9],[9],[9],[9],[9]
[9],[9],[9],[9],[9]
[9],[9],[9],[9],[9]
[9],[9],[9],[9],[9]
[9],[9],[9],[9],[9]
I hope someone can help me to solve this problem