I would like to filter a property of an object without mutating the object.
let myObject = {
propA: [1,2,3],
propB: "foo"
}
Now I would like to do something like:
myObject.propA.filter(el => el === 2)
But this only returns a filtered array and I would have to write
myObject.propA = myObject.propA.filter(el => el === 2)
in order to change my object.
But that's exactly not what I want! I would like to generate a new filtered object without mutating the old one. Could someone help me out?