-
Notifications
You must be signed in to change notification settings - Fork 3
setPath$
Subhajit Sahu edited this page Jun 28, 2020
·
3 revisions
Sets value at path in a nested object. 🏃 📼 📦 🌔 📒
Alternatives: set, set$, setPath$.
Similar: hasPath, getPath, setPath$, removePath$.
Similar: get, set, remove.
object.setPath$(x, p, v);
// x: a nested object (updated)
// p: path
// v: value
// --> xconst object = require('extra-object');
var x = {a: {b: 2, c: 3}, d: 4};
object.setPath$(x, ['d'], 40);
// { a: { b: 2, c: 3 }, d: 40 }
x;
// { a: { b: 2, c: 3 }, d: 40 }
object.setPath$(x, ['a', 'b'], 20);
// { a: { b: 20, c: 3 }, d: 40 }
object.setPath$(x, ['a', 'b', 'c'], 30);
// { a: { b: 20, c: 3 }, d: 40 } (no effect)