Javascript question.
As title says, is it OK manner to set boolean values(true
or false
) to an array and check if either one of those exits in array afterwards?
Let's say I have function that returns either true
or false
.
Sample code:(using jQuery)
var abort = [];//make an empty array
function someFunc() {
var returnVal = false;
if( some condition ) {
returnVal = true;
return returnVal;
}
return returnVal;
}
someElement.each(function() {
abort.push( someFunc() ); //push true or false in array
});
//abort array will look eventually something like...
//[true, false, true, false, false, true, ...]
//check if `true` exists in array jQuery approach
var stop = ( $.inArray(true, abort) > -1) ? true : false ;
if( stop ) {
console.log('TRUE FOUND AT LEAST ONE IN ARRAY!');
}
This seems working OK. But I was just wondering if this is the right way...