我有一个对象:
{
"x" : "a",
"y" : "b",
"z" : "c",
}
我有一个数组:['x', 'y']
。如何从上面的对象获得结果:
{
"x" : "a",
"y" : "b"
}
答案 0 :(得分:7)
您可以使用_.pick
var data = {
"x" : "a",
"y" : "b",
"z" : "c",
};
console.log(_.pick(data, ['x', 'y']));
console.log(_.pick(data, 'x', 'y'));
<script src="https://rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script>