Search
 
SCRIPT & CODE EXAMPLE
 

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); 
Comment

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); 
Comment

javascript copy 2d array

function copy2DArray(array) {
    return array.map(row => [...row]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: upload image react 
Javascript :: next router push 
Javascript :: byte to mb js 
Javascript :: javascript tofixed is not a function 
Javascript :: adding js file to reactjs 
Javascript :: loop through array in javascript 
Javascript :: Google Maps JavaScript API error: InvalidKeyMapError 
Javascript :: javascript object array contains 
Javascript :: javascript json deserialize 
Javascript :: preview upload image jquery 
Javascript :: convert date and time into epoch javascript 
Javascript :: how remove the spaces from the string, then return the resultant string 
Javascript :: regex expression to match domain name 
Javascript :: how to know which button is clicked in jquery 
Javascript :: how to make a div appear when clicked on in javascript 
Javascript :: Link vs NavLink in react-router-dom 
Javascript :: change image src using jquery 
Javascript :: get the state of a checkbox 
Javascript :: javascript loop object 
Javascript :: phaser change background color 
Javascript :: js is undefined or null 
Javascript :: insert property multiple documents mongodb 
Javascript :: change the border of an image js 
Javascript :: on click copy text 
Javascript :: uppercase in javascript 
Javascript :: js copy array into another 
Javascript :: express error middleware 
Javascript :: jszip angular 
Javascript :: what is JSON TREE 
Javascript :: upload image to firebase 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =