|
Siebel eScript Language Reference > Siebel eScript Commands > Array Objects >
Associative Arrays in Siebel eScript
Siebel eScript supports associative arrays, where the array index can be a string instead of a number. This capability is useful when you want to associate values with specific names. For example you may want to have a month's array where the elements are the names of the months and the values are the number of days in the month. To access items in an associative array, you use a string as an index. For example: array_name["color"] = "red"; array_name["size"] = 15;
An advantage of associative arrays is that they are the only arrays that can be used with the for...in statement. This statement loops through every element in an associative array or object, regardless of how many or how few elements it may contain. For more information, see for...in Statement. 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 output of this example is: November = 30 December = 31 January = 31 February = 28 Total = 120
|