我想验证一个对象,也许这个对象可以有额外的参数,但我只想要一些。什么是克隆的最佳方式。我尝试了下划线,但没有任何反应:
var object = {
name: "Pepe",
age: 25,
widget: {
top: 1,
left: 1,
other: "jeje"
}
};
var a = _.pick(object, "name", "widget.top");
console.log(a);
//Will must return: {name: "pepe", widget: {top: 1}}
答案 0 :(得分:0)
var object = {
name: "Pepe",
age: 25,
widget: {
top: 1,
left: 1,
other: "jeje"
}
};
var a = _.pick(object,'name','widget');
a.widget = _.pick(a.widget,'top');