方法一
if(Object.values(obj).length>0){
// 有值
}
方法二
let arr = []
for (let key in obj) {
arr.push(obj[key])
}
两者的比较
1 let obj = {
2 a: '',
3 b: undefined,
4 c: 1,
5 d: null,
6 "": "",
7 0: ''
8 }
9 // let obj = {}
10 let arr = []
11 for (let key in obj) {
12 arr.push(obj[key])
13 }
14 console.log(Object.keys(obj)) //(6)["0", "a", "b", "c", "d", ""]
15 console.log(Object.values(obj)) //(6)["", "", undefined, 1, null, ""]
16 console.log(arr) //(6)["", "", undefined, 1, null, ""]
仅供学习和参考,如有不同见解,欢迎在评论区中留言,期待你的指正和见解!