The easiest way I can think of is simple:
Array.prototype.isNull = function (){ return this.join().replace(/,/g,'').length === 0; }; [null, null, null].isNull();
JS Fiddle demo .
This takes an array, concatenates the elements of this array together (without join() arguments join() elements of the array along with the characters , ) to return a string, replaces all the characters in this string (using a regular expression) with empty strings, and then checks to see if length 0 . So:
[null, 3, null].isNull()
Joined to give:
',3,'
All commas are replaced (using the g flag after the regular expression) to give:
'3'
Tested if its length is 0 to give:
false
It is worth noting that there is a problem, possibly in , in proven arrays.
In addition, Felix Kling's answer is somewhat faster .
source share