implement the remove property function code example

Example 1: 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 2: implement the remove property function

function removeProperty(obj, prop) {
  
  if (obj.hasOwnProperty(prop)) { 
    delete obj[prop];
    return true;
  }

  return false;
}

Example 3: removeProperty(obj, prop)

function removeProperty(obj, prop) {
if (obj[prop] != undefined) {
    delete obj[prop];
    return true;
} else {
    return false;
}
return null;
}