Code: Select all
var thisIsObject= {
'Cow' : 'Moo',
'Cat' : 'Meow',
'Dog' : 'Bark'
};
Code: Select all
removeFromObjectByKey('Cow');
Code: Select all
var thisIsObject= {
'Cow' : 'Moo',
'Cat' : 'Meow',
'Dog' : 'Bark'
};
Code: Select all
removeFromObjectByKey('Cow');
just use delete thisisObject.cow and use a switch statement or if statements (I would use a switch statement)hannabone3445 wrote: ↑Tue Sep 21, 2021 2:39 pm Let's say we have an object with this format:I wanted to do a function that removes by key:Code: Select all
var thisIsObject= { 'Cow' : 'Moo', 'Cat' : 'Meow', 'Dog' : 'Bark' };
Code: Select all
removeFromObjectByKey('Cow');
Code: Select all
function removeFromObjectByKey(obj, propName) {
delete obj[propName];
}
var foo = { a: 'able', b: 'baker' };
removeFromObject(foo, 'b');