How can I check JavaScript arrays for empty strings?

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

    If you only care about empty strings then this will do it:

    const arr = ["hi","hello","","jj"]
    ('' in arr) //returns false
    

    the last line checks if an empty string was found in the array.

提交回复
热议问题