工作上遇到了这种情况,在这里:
https://segmentfault.com/q/1010000012715651
找到了办法
特此记录一下
const pick = (obj, arr) =>
arr.reduce((iter, val) => (val in obj && (iter[val] = obj[val]), iter), {});
let obj2 = pick(obj, ['a', 'd', 'e'])
展开:
arr.reduce((iter, val) => {
if(val in obj) {
iter[val] = obj[val];
}
return iter;
}, {});
网友评论