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
1// Creates a new object, myobj, with two properties, a and b.
2var myobj = new Object;
3myobj.a = 5;
4myobj.b = 12;
5
6// Removes the a property, leaving myobj with only the b property.
7delete myobj.a;
8console.log ('a' in myobj); // output: "false"
9