Sometimes, we want to remove value from object without mutation with JavaScript.
In this article, we’ll look at how to remove value from object without mutation with JavaScript.
How to remove value from object without mutation with JavaScript?
To remove value from object without mutation with JavaScript, we can use the rest syntax.
For instance, we write
const omitProp = (obj, prop) => {
const { [prop]: omit, ...res } = obj;
return res;
};
to create the omitProp
function that destructures the prop
property from the obj
object.
And then we get the rest of the properties in obj
with the res
object.
Finally, we return res
.
Conclusion
To remove value from object without mutation with JavaScript, we can use the rest syntax.