fas*_*ava 1 javascript object lodash
我有一个对象:
{
"x" : "a",
"y" : "b",
"z" : "c",
}
Run Code Online (Sandbox Code Playgroud)
我有一个数组:['x', 'y'].如何从上面的对象获得结果:
{
"x" : "a",
"y" : "b"
}
Run Code Online (Sandbox Code Playgroud)
您可以使用 _.pick
var data = {
"x" : "a",
"y" : "b",
"z" : "c",
};
console.log(_.pick(data, ['x', 'y']));
console.log(_.pick(data, 'x', 'y'));Run Code Online (Sandbox Code Playgroud)
<script src="https://rawgit.com/lodash/lodash/3.0.1/lodash.min.js"></script>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |