Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if all array values are blank in Javascript

I have an array like:

["", "", "", "1", "", ""]

I want to alert when all the array values are blanks, i.e, when the array is like this:

["", "", "", "", "", ""]

How can I achieve this.

like image 869
Atal Shrivastava Avatar asked May 27 '19 04:05

Atal Shrivastava


1 Answers

Try this,

["", "", "", "", "", ""].join("").length==0

If you want to remove spaces,

["", "", "", "", "", ""].join("").replace(/\s/gi,'').length==0

Note :

This will not work for inputs like ["", [], "", null, undefined, ""]

like image 192
Srinivasan Sekar Avatar answered Nov 27 '22 21:11

Srinivasan Sekar