Use the delete Keyword to Remove Object Properties question!

Tell us what’s happening:
it seems that I’m missing something in the syntax, i was trying to delete more than one key in one line and it seems that it is not working for some reason, my question is : is it wrong to do it this way?

Your code so far


let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27
};

// change code below this line
delete foods['oranges','plums','strawberries']
// change code above this line

console.log(foods);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/use-the-delete-keyword-to-remove-object-properties

To do it in one line you need:

['oranges','plums','strawberries'].forEach(key => delete foods[key]);
1 Like

this is new! so basically you are using all the keys as one object? so if i want to delete more than one i have to put them in an array. this is amazing. thank you!