Siebel eScript Language Reference > Methods Reference > Array Methods >

About Associative Arrays


An associative array is a type of array that uses a string as an index element. This capability is useful if you must associate a value with a specific name. For example, you can create a month array where the elements are the names of the months and the values are the number of days in the month.

You use a string as an index to reference items in an associative array. For example:

array_name["color"] = "red";
array_name["size"] = 15;

The associative array is the only type of array that you can use with the following type of statement:

for in

This statement loops through every element in an associative array or object, regardless of how many elements it contains. For more information, see For In Statement.

Siebel CRM uses a hash table to implement the associative array, so the elements are not in an order that an indexed array uses, and you cannot use array methods with an associative array, such as split, join, or length.

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

Siebel eScript Language Reference Copyright © 2018, Oracle and/or its affiliates. All rights reserved. Legal Notices.