我可以使用另一个 _.get 作为 lodash _.get 的默认值吗?
Can I use another _.get as the default for lodash _.get?
d = {颜色:"red",身高:"5",年龄:"200",体型:"square"}
给定一个字典,我可以像这样用 Lodash 的 _.get 得到一个值:
var myval = _.get(d, "height",null);
但是,我可以将默认值设置为另一个 _.get 吗?
像这样:
var myval = _.get(d, "length",_.get(d, "height",null));
感谢您的任何见解!
是的。
d = { color: "red", height: "5", age: "200", shape: "square" }
// Object { color: "red", height: "5", age: "200", shape: "square" }
_.get(d, 'hello', _.get(d, 'height', null));
// "5"
d = {颜色:"red",身高:"5",年龄:"200",体型:"square"}
给定一个字典,我可以像这样用 Lodash 的 _.get 得到一个值:
var myval = _.get(d, "height",null);
但是,我可以将默认值设置为另一个 _.get 吗? 像这样:
var myval = _.get(d, "length",_.get(d, "height",null));
感谢您的任何见解!
是的。
d = { color: "red", height: "5", age: "200", shape: "square" }
// Object { color: "red", height: "5", age: "200", shape: "square" }
_.get(d, 'hello', _.get(d, 'height', null));
// "5"