@mzvonar/deletein
v0.0.7
Published
Deletes value in object according to provided path and returns copy of object
Maintainers
Readme
deleteIn

Deletes value from object by path. Path can be string or array (e.g. ['user', 'profile', 'gender']).
Always returns new copy of object.
Installation
npm install @mzvonar/deletein
Parameters
deleteIn(context, path);| Name | Description |
| - | - |
| context | Object from which the value deleted |
| path | Must be Array or String. See usage |
Usage
import deleteIn from '@mzvonar/deletein';
const context = {
user: {
profile: {
gender: 'female'
},
ids: [1, 2, 3]
}
};
const newContext = deleteIn(context, ['user', 'profile', 'gender']);returns:
{
user: {
profile: {}
}
}const newContext = deleteIn(context, ['user', 'ids', 1]);returns:
{
user: {
profile: {
gender: 'female',
ids: [1, 3]
}
}
}mutableDeleteIn
If you need you can import mutableDeleteIn, which is exactly the same as deleteIn, but mutates the original context object without creating copy.
Tests
npm test
