Answers for "implement the remove property function"

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
0

implement the remove property function

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

  return false;
}
Posted by: Guest on September-30-2020
0

removeProperty(obj, prop)

function removeProperty(obj, prop) {
if (obj[prop] != undefined) {
    delete obj[prop];
    return true;
} else {
    return false;
}
return null;
}
Posted by: Guest on September-30-2020

Code answers related to "implement the remove property function"

Code answers related to "Javascript"

Browse Popular Code Answers by Language