[JS] Remove Object Keys

var thisIsObject= {
    'Cow' : 'Moo',
    'Cat' : 'Meow',
    'Dog' : 'Bark'
};
try {
  delete thisIsObject['Cow'];
} catch(e){
  thisIsObject.cow = undefined;
}
//test using developer tools F12
console.log(thisIsObject);
Output
=> {Cat: "Meow", Dog: "Bark"}
Wrapping in function for Easy Use
function delkey(obj, key){
  try {
    delete obj[key];
  } catch(e){
    obj[key] = undefined;
  }
  return obj;
}
Test Wrapped function
var thisIsObject= {
    'Cow' : 'Moo',
    'Cat' : 'Meow',
    'Dog' : 'Bark'
};

//test using developer tools F12
console.log(delkey(thisIsObject, 'Cow'));
Output wrapped function
=> {Cat: "Meow", Dog: "Bark"}

Comments

Popular posts from this blog

Find Backlink From Google Dork

Ringo Step Shotter Tutorial (CP WP)

List of weapon buff materials, effects and how it can be durango wild lands