I have
x = [false, false, true, true, false]
I want a function that returns true if there’s at least one true in the array, like this: http://jsfiddle.net/7uVWk/
x = [false, false, true, true, false];
function hasTrue(x) {
result = false;
for (var i=0; i <x.length; i++) {
result = result || x[i];
}
}
document.write(hasTrue(result));
How can I achieve this result more succinctly?
Using
Array.prototype.some(I did not write a separate function, because this syntax does already make much sense):