Reputation: 380
I have an object and I want to copy this object and remove every instance of description
from it. What is an elegant way of doing this?
here's how the object looks:
{
properties: {
a: {
value: foo,
description: bar
},
b: {
value: foo,
description: bar
}
}
Upvotes: 0
Views: 300
Reputation:
Use the second argument to JSON.parse
:
const output = JSON.parse(
JSON.stringify(input),
(key, value) => key === "description" ? undefined : value
);
A return value of undefined
from this function tells JSON.parse
to skip it.
Upvotes: 5