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 …


This content originally appeared on DEV Community and was authored by Randy Rivera

  • 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;
console.log(foods); // console will display 
{ apples: 25, bananas: 13, grapes: 35 }


This content originally appeared on DEV Community and was authored by Randy Rivera


Print Share Comment Cite Upload Translate Updates
APA

Randy Rivera | Sciencx (2021-05-12T14:29:53+00:00) Using the delete Keyword to Remove Object Properties. Retrieved from https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/

MLA
" » Using the delete Keyword to Remove Object Properties." Randy Rivera | Sciencx - Wednesday May 12, 2021, https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/
HARVARD
Randy Rivera | Sciencx Wednesday May 12, 2021 » Using the delete Keyword to Remove Object Properties., viewed ,<https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/>
VANCOUVER
Randy Rivera | Sciencx - » Using the delete Keyword to Remove Object Properties. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/
CHICAGO
" » Using the delete Keyword to Remove Object Properties." Randy Rivera | Sciencx - Accessed . https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/
IEEE
" » Using the delete Keyword to Remove Object Properties." Randy Rivera | Sciencx [Online]. Available: https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/. [Accessed: ]
rf:citation
» Using the delete Keyword to Remove Object Properties | Randy Rivera | Sciencx | https://www.scien.cx/2021/05/12/using-the-delete-keyword-to-remove-object-properties/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.