How to initialize a boolean array in javascript

You can use Array.from Array.from({length: 5}, i => i = false);


You were getting an error with that code that debugging would have caught. int isn't a JS keyword. Use var and your code works perfectly.

var anyBoxesChecked = [];
var numeroPerguntas = 5;     
for (var i = 0; i < numeroPerguntas; i++) {
  anyBoxesChecked.push(false);
}

DEMO


I know it's late but i found this efficient method to initialize array with Boolean values

    var numeroPerguntas = 5;     
    var anyBoxesChecked = new Array(numeroPerguntas).fill(false);
    console.log(anyBoxesChecked);

it can also be one solution

var boolArray = [true,false];
console.log(boolArray);