Reputation: 127
I have a Polymer 1.0 custom element which has a property called obj which is an object, say obj = { a: 1, b: 2}
How do I remove one of the keys?
I have tried this.set('obj.a', undefined) and this.set('obj.a', null)
but result is {a: null (or undefined), b: 2}
where what I want is just to remove 'a' leaving {b:2}
is there a correct way of doing it?
Upvotes: 0
Views: 473
Reputation: 3734
Use delete
. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
Example:
let x = {a: 1, b: 2, '#sss': 3};
delete x.a; // x is now {b: 2, '#sss': 3}
delete x['#sss']; // x is now {b: 2}
Upvotes: 2