Well, I guess it depends on whether a single null in the array is sufficient to fail the check. E.g, is [1,3, 5, null, 9] sufficient for that IF check above to return true? If so, then the suggestions above will work. If not, then you'll probably want to do something like this:
Array.prototype.unique = [].unique || function (a) {
return function () {
return this.filter(a)
};
}(function(a,b,c) {
return c.indexOf(a,b + 1) < 0
});
var nullArray = [null, null, null, null],
notNullArray = [null, 1, null, 2],
filtered;
if(( filtered = nullArray.unique()) && (filtered.length == 1) && (filtered[0] == null)) {
// NULL VALUE
alert( 'NULL!')
} else {
// SAFE TO WORK WITH
alert('NOT NULL!')
}
if(( filtered = notNullArray.unique()) && (filtered.length == 1) && (filtered[0] == null)) {
// NULL VALUE
alert( 'NULL!')
} else {
// SAFE TO WORK WITH
alert('NOT NULL!')
}
If the length is more than 1 then it's definitely not containing only nulls.
thnx,
Christoph
if (a.indexOf(null) == -1)