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 JSON.parse(JSON.stringify(mat))
}

let copyOfMatrix = getCopyOfMatrix(matrix); 
 
PREVIOUS NEXT
Tagged: #js #copy #array
ADD COMMENT
Topic
Name
3+8 =