how to delete a property from a javascript object code example

Example 1: Delete Properties from a JavaScript Object

var ourDog = {
  "name": "Camper",
  "legs": 4,
  "tails": 1,
  "friends": ["everything!"],
  "bark": "bow-wow"
};

delete ourDog.bark;

Example 2: javascript remove object key

var obj = {a: 5, b: 3};
delete obj["a"];
console.log(obj); // {b: 3}

Example 3: how to delete a property from a javascript object

var person = {
  firstName:"John",
  lastName:"Doe",
  age:50,
  eyeColor:"blue"
};

delete person.age;  // or delete person["age"];

// Before deletion: person.age = 50, after deletion, person.age = undefined

Tags:

Misc Example