Answers for "javascript remove property from object"

39

javascript remove property from object

var person = {"first_name": "Billy","last_name": "Johnson"};
delete person.last_name; //delete last_name property
Posted by: Guest on July-19-2019
7

javscript remove a property

var myObject = {
    "name": "jon",
    "gender": "male",
    "registered": "yes"
};
delete myObject.gender;

console.log(myObject);

//other methods
delete myObject.gender;
// or,
delete myObject['gender'];
// or,
var prop = "gender";
delete myObject[prop];
Posted by: Guest on July-06-2020
2

how to remove property from object javascript

let myObject = {
  "ircEvent": "PRIVMSG",
  "method": "newURI",
  "regex": "^http://.*"
};

const {regex, ...newObj} = myObject;

console.log(newObj);   // has no 'regex' key
console.log(myObject); // remains unchanged
Posted by: Guest on October-01-2021
11

how to remove a property from an object in javascript

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"}
Posted by: Guest on April-25-2020
6

Delete Properties from a JavaScript Object

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

delete ourDog.bark;
Posted by: Guest on July-19-2020
5

javascript remove object key

var obj = {a: 5, b: 3};
delete obj["a"];
console.log(obj); // {b: 3}
Posted by: Guest on June-03-2020

Code answers related to "javascript remove property from object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language