I have an object
let myObj = {"info1": "", "info2": "", "info3": "", ......}
Here I want to remove info1
and info2
. I tried splice
, but it is throwing error. The pop
method is also not working. How can I achieve that?
I have an object
let myObj = {"info1": "", "info2": "", "info3": "", ......}
Here I want to remove info1
and info2
. I tried splice
, but it is throwing error. The pop
method is also not working. How can I achieve that?
You can achieve this various ways:
const data = { "info1": "", "info2": "", "info3": "" };
delete data.info1;
delete data.info2;
console.log(data);
const data = { "info1": "", "info2": "", "info3": "" };
const ignore = ['info1', 'info2'];
const copy = Object.fromEntries(Object.entries(data)
.filter(([k, v]) => !ignore.includes(k)));
console.log(copy);
const data = { "info1": "", "info2": "", "info3": "" };
const { info1, info2, ...copy } = data;
console.log(copy);