delete
OperatorYou can use the delete
operator to completely remove the properties from the JavaScript object. Deleting is the only way to actually remove a property from an object.
Setting the property to undefined
or null
only changes the value of the property. It does not remove property from the object. Let's take a look at the following example:
<script>
var person = {
name: "Harry",
age: 16,
gender: "Male"
};
// Deleting a property completely
delete person.age;
alert(person.age); // Outputs: undefined
console.log(person); // Prints: {name: "Harry", gender: "Male"}
// Setting the property value to undefined
person.gender = undefined;
alert(person.gender); // Outputs: undefined
console.log(person); // Prints: {name: "Harry", gender: undefined}
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
PHP array_combine method example
In this tutorial article, we have PHP ar...How to Add Remove Items from Javascript Array
There are four basic methods t...Image Crop and Upload using Croppie jQuery plugin
In every social networking website, ther...PHP - Create file if it doesn’t already exist
In this article, we will use PHP to chec...Laravel Dynamically Add or Remove Input Fields jQuery
In this article, we will share with you...