Answers for "copy double array js"

1

js copy 2d array

let matrix = [
  [0,0,0,0,0],
  [0,0,0,0,0],
  [0,0,0,0,0],
  [0,0,0,0,0],
]
// copies just values, not references!
function getCopyOfMatrix(mat) {
  return mat.map(row => row.map(col => col))
}

let copyOfMatrix = getCopyOfMatrix(matrix);
Posted by: Guest on July-14-2021
0

how to double array data in js

function double (arr){
    let newArr = [];
    for(let i = 0; i < arr.length; i++){
        newArr.push(arr[i] * 2);
    }
    console.log(newArr) ;
}
console.log(double([3,4,5]));
Posted by: Guest on April-22-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language