How can I assign a variable without referencing it in typescript?
let miObjeto:Object = res; //Respuesta de función de API que me devuelve un objeto cualquiera.
miObjeto.cantidad = 2;
let auxObjeto:Object = miObjeto;
miObjeto.cantidad = 5;
console.log(auxObjeto.cantidad) // Devuelve 5 referenciando el cambio de miObjeto en vez de 2.
You can use the spread syntax to get an independent copy of the object:
I leave you an online example at the following URL:
I have finally managed to fix it using JSON as follows.
the solution you mention
can give errors depending on the case
and problems with
you can use lodash