We mentioned delete briefly in our discussion on arrays. We talked about that. If you delete an element from an array using the Delete keyword, it can create a sparse array, which is basically an array that has an index or indices could be multiple, that do not contain anything, though you can use delete with arrays to to remove elements. The main purpose of delete is for removing properties from objects. So let's take a look at how that is done. You open the console and then I'm going to create an object just going to copy the code.
So this object will have first name, last name, so several key value pairs first name, last name, full name as a function, like we've been doing in the past. Past age and birthdate. Go ahead and press return we have an object created. You can see it by typing in user. I'm gonna go ahead and clear this. Now let's say that I wanted to remove the birth date no longer want birthdate as a part of our object that can simply be done like this.
Now if I display user again and we open it up, we can see birthdate is no longer part of that we have age, first name, last name, and we have the full name function but birthdate is no longer there. Let's say I also want to delete the function, same process. It doesn't change no matter what type of property, we're looking at. Now because I'm deleting it, I would not put the parentheses at the end parentheses would indicate to invoke the function. I simply want to remove it. press return display the object and that is now gone.
So that's when you can use delete. That's how you can remove properties from an object. Alright, let's move to the next topic.