Answers for "how to combine a 2d array into a 1d array in 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

Code answers related to "Javascript"

Browse Popular Code Answers by Language