I have an array of objects in which I have to keep an object always and remove everything else.
columnList = [];
//this object values remains same
defaultObject = {
key1: value1,
key2: value2
}
this.columnList.push(defaultObject);
someMethod(){
this.columnList = []; //emptying array
//this object's values keep on changing
anotherObject = {
key1: value1,
key2: value2
}
this.columnList.push(anotherObject);
}
In the columnList array I need to keep the defaultObject always as first one and replace anotherObject based on some other logic. Here when I clear the array it removes defaultObject as well, which I want to prevent. I only want to remove anotherObject from array when the method call happens. Any suggestions? Thanks.