Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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); 
 
PREVIOUS NEXT
Tagged: #js #copy #array
ADD COMMENT
Topic
Name
9+6 =