+ 1
How to remove a property of an object in an array in javascript ?
const menu =[ { id:2, title:"pizza", discount : ["./food-img/discount15.png" , "./food-img/discount.png"] } ] I want to remove discount property just in this object , how can i do that ?
3 Réponses
+ 1
As I understand You want to get rid of key:value pair with key discount. Then I assume You’ll have to use delete operator:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
So I’d guess it could look like:
delete menu[0].discount
Where 0 is obviously the index of this element.
You can also keep the discount key and just empty the discount array to keep the same look of all objects in the menu array if that’s what You’re aiming for
0
Thanks you so much , but when i make that as empty array it shows the images but not loaded images ,but i wanna remove them completely