1let myObject = {
2 "ircEvent": "PRIVMSG",
3 "method": "newURI",
4 "regex": "^http://.*"
5};
6
7const {regex, ...newObj} = myObject;
8
9console.log(newObj); // has no 'regex' key
10console.log(myObject); // remains unchanged
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;
1// ES6 should be in search keyword
2Reflect.deleteProperty(myObj, propNameString);
3// Source referece in Chinese.