magic-path
v0.1.0
Published
Get Values from JS Objects magically
Downloads
15
Maintainers
Readme
How to Use
Get value😎
...
import { get } from 'magic-path'; // import
...
.
...
const yourDataObject = {
name: "sherlock holmes",
address: {
plotNo: "221B",
street: "baker street"
}
}
get(yourDataObject,"name"); // sherlock holmes
get(yourDataObject,"address"); // ---address Object
get(yourDataObject,"address.plotNo"); // 221B
const yourArray = [{name: "SHERLOCK"},{name: "WATSON"}, {name: "moriarty"}];
get(yourArray,["name"]); // ["SHERLOCK", "WATSON","moriarty"]
...
Set value😎
...
import { set } from 'magic-path'; // import
...
.
...
const yourDataObject = {
name: "sherlock holmes",
address: {
plotNo: "221B",
street: "baker street"
}
}
const newData = set("family.brother.name",'mycroft',yourDataObject);
{
name: "sherlock holmes",
family: {
brother: {
name: mycroft;
}
}
address: {
plotNo: "221B",
street: "baker street"
}
}
...