I have a Class in Angular 2 and I need two variables with the same json value, but I will need to change one and I need to keep the another one as a backup of the first, like this:
export class Table {
var1: any;
var2: any;
}
Then, with a request to API:
ajax_request().then(data => {
this.var1 = data;
this.var2 = data;
});
If I make changes in this.var2, this.var1 will be changed too.
To avoid this, I'm making:
this.var1 = data;
this.var2 = JSON.stringify(this.var1);
this.var2 = JSON.parse(this.var2);
But I know It's not performance-friendly. What is the appropriated way to do that?