1var person = {"first_name": "Billy","last_name": "Johnson"};
2delete person.last_name; //delete last_name property
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"}
1const names = {
2 father: "Johnny",
3 brother: "Billy",
4 sister: "Sandy"
5}
6
7delete names.father
8// { brother: "Billy", sister: "Sandy" }
9
10delete names["father"]
11// { brother: "Billy", sister: "Sandy" }
1const names = {
2 father: "Johnny",
3 brother: "Billy",
4 sister: "Sandy"
5}
6
7const newNames = Object.keys(names).reduce((object, key) => {
8 if (key !== "father") {
9 object[key] = names[key]
10 }
11 return object
12}, {})
13
14// { brother: "Billy", sister: "Sandy" }