Array Object in eScript

An array is a special class of object that holds several values rather than one. The values could range from simple data structures to complex ones. The later is called vectors.

Values stored in an array are refernced by index numbers assigned to that value. Each value in an array is called an element. Array indices can be either numbers or strings. Arrays can be single dimensional or multi-dimensional in nature.

var arrMyArr = new Array(); // Defines an array object

arrMyArr[0] = “Single Dimensional first value”;

arrMyArr[1][2] = “2-Dimensional Array referencing 2nd row and 3rd column”

Operations supported on Array objects in eScript:

1. Array join() Method:
Syntax: arrMyArr.join([separatorString]):- A string of characters to be placed between consecutive elements of the array; if not specified, a comma is used.

2. Array length property:
Syntax: arrMyArr.length :- Returns an integer value which equals the largest index of array, +1.

3. Array pop() Method:
Syntax: arrMyArr.pop() :- Similar to the pop method we have for stacks. It removes the last element from the array and returns it. If the array has no elements left, it returns “undefined”.

4. Array push() Method:
Syntax: arrMyArr.push(“Element”) :- Appends the element(s) passed onto the end. Returns the updated index of the last element.

5. Array reverse() Method:
Syntax: arrMyArr.reverse() :- Reverses the elements in the array so that last element becomes the first element.

6. Array sort() Method:
Syntax: arrMyArr.sort(“Function to compare and decide sort mechanism”)

7. Array splice() Method:
Syntax: arrMyArr.splice(StartIndex, NoOfElements) :- Returns another array of the elements removed from the main array.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s