I tried making a function to do just this, since I ran into similar problems. However, I keep getting a syntax error in the console, and it isn’t working to complete the challenge. I don’t see any syntax errors or anything that shouldn’t work. Anyone have any ideas what would make this work?
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/use-the-delete-keyword-to-remove-object-properties
let foods = {
apples: 25,
oranges: 32,
plums: 28,
bananas: 13,
grapes: 35,
strawberries: 27
};
// change code below this line
function Delete(arr, objName) {
let newName = objName.replace(/"+/g, "");
while (let i = 0; i < arr.length; i++) {
delete newName[arr[i]];
}
}
Delete(["oranges", "plums", "strawberries"], "foods");
// change code above this line
console.log(foods);