_.pickBy
Creates an object composed of the object properties predicate returns truthy for.
- var object = { 'a': 1, 'b': null, 'c': 3, 'd': false, 'e': undefined };
- // Underscore/Lodash
- var result = _.pickBy(object);
- console.log(result)
- // output: {a: 1, c: 3}
- // Native
- function pickBy(object) {
- const obj = {};
- for (const key in object) {
- if (object[key] !== null && object[key] !== false && object[key] !== undefined) {
- obj[key] = object[key];
- }
- }
- return obj;
- }
- var result = pickBy(object);
- console.log(result)
- // output: {a: 1, c: 3}
Browser Support
✔ | ✔ | ✔ | 6.0 ✔ | ✔ | ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .