How can I check JavaScript arrays for empty strings?

前端 未结 16 2041
面向向阳花
面向向阳花 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:06

    You can check by looping through the array with a simple for, like this:

    function NoneEmpty(arr) {
      for(var i=0; i

    You can give it a try here, the reason we're not using .indexOf() here is lack of support in IE, otherwise it'd be even simpler like this:

    function NoneEmpty(arr) {
      return arr.indexOf("") === -1;
    }
    

    But alas, IE doesn't support this function on arrays, at least not yet.

提交回复
热议问题