Set deep property by key chaining and manipulate given object.
import set from '@util-funcs/object-set';
npm i @util-funcs/object-set --save
or
yarn add @util-funcs/object-set
let data = {};
data = set(data, 'a.b.c.d.e', 'test data');
// output:
{
a: {
b: {
c: {
d: {
e: 'test data'
}
}
}
}
}
Object will be manipulate and return it same reference. You do not have to assign return data to a variable.
let data = {};
set(data, 'a.b.c.d.e', true);
// data:
{
a: {
b: {
c: {
d: {
e: true
}
}
}
}
}
npm test
We use SemVer for versioning.
- Ahmet ATAY - Initial work
This project is licensed under the MIT License - see the LICENSE.md file for details