how to remove property from javascript object code example

Example 1: javascript remove property from object

var person = {"first_name": "Billy","last_name": "Johnson"};
delete person.last_name; //delete last_name property

Example 2: 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];

Example 3: how to remove property of object in javascript without delete

const names = {
  father: "Johnny",
  brother: "Billy",
  sister: "Sandy"
}

const newNames = Object.keys(names).reduce((object, key) => {
  if (key !== "father") {
    object[key] = names[key]
  }
  return object
}, {})

// { brother: "Billy", sister: "Sandy" }