DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Randy Rivera
Randy Rivera

Posted on

Using the delete Keyword to Remove Object Properties

  • Now you know what objects are and their basic features and advantages. In short, they are key-value stores which provide a flexible, intuitive way to structure data, and, they provide very fast lookup time.
  • In earlier posts, we have both added to and modified an object's key-value pairs.
  • Here we will see how we can remove a key-value pair from an object. Let's revisit our foods object example one last time. If we wanted to remove the oranges, plums, and strawberries keys, we can remove it by using the delete keyword like this:
let foods = {
  apples: 25,
  oranges: 32,
  plums: 28,
  bananas: 13,
  grapes: 35,
  strawberries: 27

delete foods.oranges;
delete foods.plums;
delete foods.strawberries;
Enter fullscreen mode Exit fullscreen mode
console.log(foods); // console will display 
{ apples: 25, bananas: 13, grapes: 35 }
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

This post blew up on DEV in 2020:

js visualized

🚀⚙️ JavaScript Visualized: the JavaScript Engine

As JavaScript devs, we usually don't have to deal with compilers ourselves. However, it's definitely good to know the basics of the JavaScript engine and see how it handles our human-friendly JS code, and turns it into something machines understand! 🥳

Happy coding!