Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript : How to define an array of booleans with 60 elements in it [closed]

Tags:

javascript

In JavaScript : How do I define an array of booleans of a certain length without having to define manually, e.g. an array with 60 elements in it ?

like image 769
sbguy Avatar asked Mar 24 '12 02:03

sbguy


2 Answers

var anArrayOfBooleansWith60ElementsInIt = [true, true, true, true, true, true, true, true,  true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,  true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,  true, true, true, true, true, true, true, true, true, true, true, true, true, true, true,  true, true, true, true, true, true, false]; 
like image 167
Neil McGuigan Avatar answered Sep 21 '22 05:09

Neil McGuigan


JavaScript is loosely typed, so you can't really do that. You can of course create a 60 element array.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array

var a = new Array(60); 

And then you could just fill it with false or something.

for (var i = 0; i < a.length; ++i) { a[i] = false; } 
like image 43
Corbin Avatar answered Sep 21 '22 05:09

Corbin