Removing data in array also remove data in Observable

Viewed 29

I am trying to get data from Observable and move it to an array. then I would like to try to splice 1 item in the array, but somehow the item inside the observable is also removed. is there anything that I did wrong?

assume this is the value of my observable data:

dataObs = {
   values:[{id: 1, name: orange},
           {id: 2, name: apple},
           {id: 3, name: peach}], ...}

Here is my code

        let dataArr = new Array<any>;

        this.dataObs.subscribe(val => dataArr = val);
        dataArr.forEach((element, index) => {
           if(element.id == 1) dataArr.splice(index, 1) //delete orange in the array
           });

somehow, the orange in observable also deleted.

dataObs = {
   values:[{id: 2, name: apple},
           {id: 3, name: peach}], ...}
1 Answers
Related