Welcome to ZaiNaLe Developer Community-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

如何判断数组中的对象的每一个key都有值

[{a:1,b:''},{a:'',b:''}]


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
let arr = [{a:1,b:''},{a:'',b:''}], isNull = false;
arr.map(item => {
    let keys = Object.keys(item);   // ["a", "b"]
    keys.map(k => {
       if (!item[k]) isNull = true
    })
})

consol.log(isNull); // 如果为true,则有空值

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to ZaiNaLe Developer Community-Open, Learning and Share
...