Ask coding questions

← Back to all posts
IF Statement Loop JS
schoolonlinebee

I want to loop through an array in a js if statement. Like check to see if there is atleast one true value in the array and set a value.

let array = [
true,
false,
false,
false,
]

if (
// Check if is there atleast one true value in the array
){
myPlayer.value = 'blue'
}

Voters
schoolonlinebee
Comments
hotnewtop
MrVoo

Try this: array.includes(true)

schoolonlinebee

@MrVoo thank you