d = {color:“red”,身高:“5”,年龄:“200”,形状:“square”}
给定一个字典,我可以用Lodash的_.get得到一个值,如:
var myval = _.get(d, "height",null);
但是,我可以将默认值设置为另一个_.get吗? 像这样:
var myval = _.get(d, "length",_.get(d, "height",null));
感谢您的任何见解!
答案 0 :(得分:1)
是
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"