My last article looked at Strings, regular expressions and other objects. This article will finish this series by looking at Arrays, Functions, and techniques for processing objects.
The purpose of an array is to contains numbered values NOT named values.
In Sage CRM the majority of the work we will do, you will be using other objects rather than Arrays.
But with Array Values are accessed via the [ ] operator
First element of array is 0
arrayTest = 1;
arrayTest = “Hello World”;
arrayTest = arrayA + arrayA;
Arrays can hold all data type including other objects.
You can see the way in which we can define an array.
The type of object with which you will become very familiar is a function.
You can see here I have defined a function which is bundled bit of behaviour for use in checking the case of strings. This will see whether these are correctly capitalised.
This example assumes that it is for use in custom content but it could be used within any server-side code.
It makes use of the methods and properties of string objects.
Handling Objects: while, do while and for loops
Consider the code below
This is a “while” loop
The while loop loops through a block of code as long as a specified condition is true.
This in comparison with the ‘while’ loop is the ‘do while’
In a “do while” loop the contents of the loop is always done at least once. This example works because a company is always created with a person.
This is a “for” loop.
This is useful where we need to cycle through all of the properties of an object looking for a particular value.
I hope you have found these articles of interest.
The links to the other articles in the series are listed below
- The syntax of the language and the different objects available.
- The objects that are available within the Browser.
- Binding a script to an event.
- Conditional behaviour and compound statements.
- Another look at Strings, regular expressions and other objects.
- Arrays, Functions, and techniques for processing objects.