I need to loop over my array and set all the vars to false or true. I have tried numerous options, none of which are working and it’s clearly my lack of javascript syntax knowledge..Please take a look at this:
var closeAllCells = [IncomeOpen = "false",
RehabOpen = "false",
AttendantCareOpen = "false",
HomeMaintenanceOpen = "false",
DependantCareOpen = "false",
IndexationOpen = "false",
DeathFuneralOpen = "false",
ComprehensiveOpen = "false",
CollisionOpen = "false",
LiabilityOpen = "false",
DCPDOpen = "false"];
So my thinking is that I can just loop over this as follows
for (var i=0;i<closeAllCells.length;i++)
{
closeAllCells[i] = true; // or false if I wished
}
In your example, you are creating an array that contains the values assigned to a bunch of global variables, the array looks like this:
[false, false, false, false, false, false, ...].You are looking to use an object literal to store your values as properties an object, for example:
As you can see, we are using a
for...inloop here, the purpose of this statement is to enumerate object properties.You can access the individual properties also like this:
You may wonder why we need to call the
hasOwnPropertymethod, well that’s to ensure that only own properties (properties that exist physically on the object, the ones we defined) are enumerated, not any inherited property.See also:
for...instatement