how to remove a property from an object in javascript


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

delete obj.firstname;

var string = "Hello World";
var substring = "Hello";
if (string.indexOf(substring) != -1) {
//Code here
}

var person = {
name: "Harry",
age: 16,
gender: "Male"
};

// Deleting a property completely
delete person.age;
alert(person.age); // Outputs: undefined
console.log(person); // Prints: {name: "Harry", gender: "Male"}

www.codegrepper.com
www.stackoverflow.com