1var person = {"first_name": "Billy","last_name": "Johnson"};
2delete person.last_name; //delete last_name property
1var myObject = {
2 "name": "jon",
3 "gender": "male",
4 "registered": "yes"
5};
6delete myObject.gender;
7
8console.log(myObject);
9
10//other methods
11delete myObject.gender;
12// or,
13delete myObject['gender'];
14// or,
15var prop = "gender";
16delete myObject[prop];
1 var person = {
2 name: "Harry",
3 age: 16,
4 gender: "Male"
5 };
6
7 // Deleting a property completely
8 delete person.age;
9 alert(person.age); // Outputs: undefined
10 console.log(person); // Prints: {name: "Harry", gender: "Male"}
1var ourDog = {
2 "name": "Camper",
3 "legs": 4,
4 "tails": 1,
5 "friends": ["everything!"],
6 "bark": "bow-wow"
7};
8
9delete ourDog.bark;
1var person = {
2 firstName:"John",
3 lastName:"Doe",
4 age:50,
5 eyeColor:"blue"
6};
7
8delete person.age; // or delete person["age"];
9
10// Before deletion: person.age = 50, after deletion, person.age = undefined
11