How to initialize an array of boolean values in JavaScript

2 Answers

0 votes
const arr = new Array(4).fill(false);

console.log(arr);
  
   
    
      
      
/*
run:
  
[false, false, false, false]
      
*/

 



answered May 12, 2022 by avibootz
0 votes
const arr = new Array(4);

for (let i = 0; i < arr.length; i++) {
  	arr[i] = false;
}

console.log(arr);

   
    
      
      
/*
run:
  
[false, false, false, false]
      
*/

 



answered May 12, 2022 by avibootz
...