I have a 2D array:
var array = [[\"a\", \"b\", \"c\"],[\"a\", \"b\", \"c\"],[\"a\", \"b\", \"c\"]]
I want to delete an entire column of thi
Useful code snipped that creates an independent copy of an array
use slice method inside map. Here is an example:
let arrayA = ['a', 'b', 'c', 'd']
let arrayB = arrayA.map((val) => {
return val.slice()
})
arrayB[2] = 'Z';
console.log('--------- Array A ---------')
console.log(arrayA)
console.log('--------- Array B ---------')
console.log(arrayB)
Note: In Angular 10, I used different methods to get an independent copy of an array but all failed. Here are some of them:
arrayB.push(arrayA) // failed
arrayB = Object.create(arrayA) // failed
arrayB = arrayA.splice() // failed
All failed methods were copying references along with data.