Example of Using an Associative Array

The following example creates an associative array of months and days, and totals the number of days:

// open file
var fp = Clib.fopen("c:\\months.log", "at");
// populate associative array
var months = new Array();
months["November"] = 30;
months["December"] = 31;
months["January"] = 31;
months["February"] = 28;
// iterate through array items
var x;
var total = 0;
for (x in months)
   {  
    // write array items name and value to file
    Clib.fputs(x + " = " + months[x] + "\n",fp);
    // Add this month’s value to the total
    total = total + months[x];
   }
Clib.fputs ("Total = " + total + "\n",fp);
//close file
Clib.fclose(fp);

The following is the output from this example:

November = 30
December = 31
January = 31
February = 28
Total = 120