“JavaScript Copy 2D -Array” Code-Antworten

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); 
Ill Ibex

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); 
Ill Ibex

JavaScript Copy 2D -Array

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

Ähnliche Antworten wie “JavaScript Copy 2D -Array”

Fragen ähnlich wie “JavaScript Copy 2D -Array”

Weitere verwandte Antworten zu “JavaScript Copy 2D -Array” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen