How can I check JavaScript arrays for empty strings?

前端 未结 16 2070
面向向阳花
面向向阳花 2020-12-15 07:26

I need to check if array contains at least one empty elements. If any of the one element is empty then it will return false.

Example:

var my_arr = ne         


        
16条回答
  •  难免孤独
    2020-12-15 08:16

    function containsEmpty(a) {
        return [].concat(a).sort().reverse().pop() === "";
    }
    alert(containsEmpty(['1','','qwerty','100'])); // true
    alert(containsEmpty(['1','2','qwerty','100'])); // false
    

提交回复
热议问题