Table 29 Example Usage of the Array Function Example Array Function Description

Table 29 example usage of the array function example

This preview shows page 80 - 83 out of 334 pages.

Table 29. Example Usage of the Array Function Example Array Function Description var a = new Array();an This code initializes the following variable as an array with no elements: a The parentheses are optional. var b = new Array(31); This code creates an array that includes 31 array elements. If you must create an array that includes a predefined number of array elements, then you can use the number of elements as a argument of the Array function when you declare the array. var c = new Array(5, 4, 3, 2, 1, "blast off"); This code creates an array that includes six elements: c[0] is set to 5. c[1] is set to 4. And so forth up to c[5], which is set to the string "blast off". The first element of the array is c[0]. It is not c[1]. You can pass elements to the Array function, which creates an array that contains the arguments you pass.
Image of page 80
Methods Reference Array Methods Siebel eScript Language Reference Version 8.1, Rev. A 81 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 Add Array Elements Method The Add Array Elements method adds the elements that you define in the element argument to the end of the array. It adds these elements in the order that you define these arguments. Format arrayName .push([ element1 , element2 , ..., elementn ])
Image of page 81
Siebel eScript Language Reference Version 8.1, Rev. A Methods Reference Array Methods 82 Table 30 describes the arguments for the Add Array Elements method. Example The following example includes the Add Array Elements method: var a = new Array(1,2); TheApplication().RaiseErrorText(a.push(5,6) + " " + a); // Displays 4 1,2,5,6, the length and the new array. Concatenate Array Method The Concatenate Array method concatenates all the elements of an array into a string. It returns a concatenated string that includes individual array element values that are separated by commas. It does not include any input arguments. Format concat() toLocaleString() Converting a Concatenated Array to Another Language The toLocaleString statement works just like the concat statement but it converts the string to another language according to the locale setting. Example The following example includes the Concatenate Array method: var v = new Array; v[0] = 7; v[1] = 3; v.concat(); // The result would be "7,3" Create Array Elements Method The Create Array Elements method creates a string of array elements. It returns a string that contains the array elements. A comma or the separatorString argument separates each element.
Image of page 82
Image of page 83

You've reached the end of your free preview.

Want to read all 334 pages?

  • Summer '16
  • Oracle
  • Type system, Siebel, Siebel eScript

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes