Angular 8 with Firebase: Array .map () .slice () Do not work. Hi. I have been trying to make a copy of an array using .map () and .slice () in Angular 8, but using these methods I find that the copied array still has the reference to the original array.
I don't know if I'm doing it wrong, or these methods don't work in Angular 8.
// Iniciamos la escucha de los cambios de la data del usuario
if (!this.$userData) {
this.$userData = this.userService.user().valueChanges().subscribe(data => {
if (data) {
this.userData = Object.assign({}, data);
const temp = data.operationsList.map((x) => {
x.bank = 'Popular';
return x;
});
console.log(this.userData.operationsList, temp);
if (!this.userData.validated) {
this.router.navigate(['register/pendingValidation']);
}
}
});
}
console.log:
(2) [{…}, {…}]
0: {bank: "Popular", commission: 0, country: "ve", countryAllowed: "all", maximum: 0, …}
1: {bank: "Popular", commission: 0, country: "ve", countryAllowed: "all", maximum: 0, …}
(2) [{…}, {…}]
0: {bank: "Popular", commission: 0, country: "ve", countryAllowed: "all", maximum: 0, …}
1: {bank: "Popular", commission: 0, country: "ve", countryAllowed: "all", maximum: 0, …}
When modifying the copied array, the changes are also reflected in the original array.