+ 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 ?

18th Feb 2022, 8:59 PM
fateme kamarei
fateme kamarei - avatar
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
19th Feb 2022, 5:44 AM
Seba L
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
19th Feb 2022, 4:05 PM
fateme kamarei
fateme kamarei - avatar