Previous Document Next Document

What query methods are supported for arrays?

All common query methods (see the section “What common query methods are supported?”) are supported for arrays.

The following query methods are also supported for arrays:

Method
Description
Example
Result
array.Count()
Returns the number of elements in the array
array(1,2,3).count
3
array.Empty()
Returns True if the array contains no elements
array(1,2,3).empty
False
 
 
array().empty
True
array.Add(object)
Adds an object to the end of the array
 
 
array.Item(int)
Gets the object identified by the index. The index is 1-based.
array(1,3,4).item(2)
3
array.Join(string)
Joins the array elements into a string by using the specified delimiter string
array(1,3,4).join(', ')
'1, 3, 4'
array.ForEach(object, expression, [object])
Evaluates the specified expression for each element of the array and returns the result of the evaluation. This is an iterative process; the result of evaluation of the previous iteration is passed to the current one.
array(1,2,3,4).foreach(0, $lasteval + $item)
10
[sums up all of the array’s elements]
 
The expression being evaluated can use a special iterator object, which has the following member variables:
  • $item — the current array element
  • $index — the 1-based index of the current array element
  • $lasteval — the result of evaluation of the previous iteration
  • $data — additional data object passed in by the caller
array('this', 'is','an', 'example').foreach('Result:', $lasteval + ' ' + $item.ToTitle)
Result: This Is An Example
 
The first parameter specifies the initial value passed in through the $lasteval variable to the first element iteration. The second parameter is the expression being evaluated for each array element. The last optional parameter is the additional data object passed in as the $data variable; if this parameter is omitted, $data variable will contain a null object.
 
 
array.Filter(expression, [object])
Creates a subset of array elements by including only the elements for which the specified Boolean expression evaluates to True. The expression can use the same iterator object as in the ForEach method to get the value of the current element and the custom data passed in as the second parameter.
array(1,2,3,4,5).filter($item > 3)
array(4, 5)
array.Convert(expression, [object])
Changes the value of each element of the array to the result of evaluation of the given expression
array(1,2,3,4).convert($item * 2)
array(2, 4, 6, 8)
array.Find(object)
Finds an object in the array and returns True if it is found
array(1,2,3,4).find(3)
True
array.IndexOf(object)
Finds an object in the array and returns the 1-based index of the array element found, or 0 if not found
array('apple', 'orange', 'pear').indexof('orange')
2

Previous Document Next Document Back to Top

Copyright 2007 Corel Corporation. All rights reserved.