mpath
mpath copied to clipboard
set() does not create a nested structure
Perhaps this is expected behaviour, but I do not understand why this does not work:
const obj = {};
mpath.set('a.b', 3, obj);
console.log(obj); // => {}
It returns an empty object {}
, while I was expecting it to return { a: { b: 3 } }
. Using .get()
it works the other way around:
const obj = { a: { b: 3 } };
console.log(mpath.get('a.b', obj)); // => 3