removeKey
Method is IN-PLACE. Also, compatible to call with Array
Definition
function removeKey(...keys: string[]) : this;
Example
Another simple one... You can provide a list of keys or only single key to remove in the object
import '@marthvon/protopp';
// or
import '@marthvon/protopp/objectpp/methods/removeKey.js';
const o = { a: 1, b: 2, c: 3, d: 4 };
console.log(o.removeKey('a'));
// Outputs { b: 2, c: 3, d: 4 }
console.log(o.removeKey('b', 'c'));
// Outputs { d: 4 }
console.log(o);
// Outputs { d: 4 }
// Notice that the changes are inplace,
// hence it doesn't create a new array when you remove a key
if you need it to make another copy... I would suggest using it inconjunction with the .deepCopy method, Or performing a shallow copy
o.deepCopy().removeKey(...);
// Or, if you want to preserve the references then do a shallow copy
{ ...o }.removeKey(...);
Learn more of the difference betweene .deepCopy and .deepCopyP Here