_.isEmpty
Checks if value is an empty object or collection.Note this is not evaluating a Set or a Map
- // Lodash
- console.log(_.isEmpty(null)
- // output: true
- console.log(_.isEmpty('')
- // output: true
- console.log(_.isEmpty({})
- // output: true
- console.log(_.isEmpty([])
- // output: true
- console.log(_.isEmpty({a: '1'})
- // output: false
- // Native
- const isEmpty = obj => [Object, Array].includes((obj || {}).constructor) && !Object.entries((obj || {})).length;
- console.log(isEmpty(null)
- // output: true
- console.log(isEmpty('')
- // output: true
- console.log(isEmpty({})
- // output: true
- console.log(isEmpty([])
- // output: true
- console.log(isEmpty({a: '1'})
- // output: false
Browser Support for Array.prototype.includes()
47.0 ✔ | 14.0 ✔ | 43.0 ✔ | ✖ | 34.0 ✔ | 9.0 ✔ |
当前内容版权归 you-dont-need 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 you-dont-need .