23/02/21 23:07:45.74 6tAoYaOK.net
>>915
>そのarray[i][j]の[j]を入れるとindexOfにしてもincludesにしてもうちの環境?では何故かエラー出て
たぶん配列の添字が範囲外になってるんだろうけど
for文よりfor ofとかforEachのほうがシンプルにかける
const array2 = [];
for(let row of array) {
let cols = [];
for(let col of row) {
if(before.includes(col)) {
cols.push(after[before.indexOf(col)]);
}
else {
cols.push(col);
}
}
array2.push(cols);
}
const array2 = [];
array.forEach(function(row, i) {
row.forEach(function(col, j) {
if(before.includes(col)) {
array[i][j] = after[before.indexOf(col)];
}
});
});