I have instance of class:
let i = new I();
before adding to array I need clone it, create a copy:
arr.push(i);
I have tried:
Object.assign({}, i)
I have instance of class:
let i = new I();
before adding to array I need clone it, create a copy:
arr.push(i);
I have tried:
Object.assign({}, i)
You can try the following code, it should work.
let i = new I();
//const clone = Object.assign({}, i);
//arr.push(clone);
//const clone = JSON.parse(JSON.stringify(i));
//arr.push(clone);
const clone = Object.create(
Object.getPrototypeOf(i),
Object.getOwnPropertyDescriptors(i)
);
arr.push(clone);