Class: CGArray

CGArray

CGArray is essentially an array for holding CGV Objects. Any method that works on an Array will also work on a CGArray.

If a single array is provided it will be converted to an CGArray. If mulitple elements are provided, they will be added to the new CGArray.

Examples

const a1 = new CGArray(1, 2, 3);
=> CGArray [1,2,3]

const a2 = new CGArray([1,2,3])
=> CGArray [1,2,3]

new CGArray()

Members

first

Return the first element of the CGArray or "undefined" if the array is empty

last

Return the last element of the CGArray or "undefined" if the array is empty

Methods

staticCGArray.arrayerize(object){CGArray}

Returns the object incased as a CGArray. If it's already a CGArray, it is returned untouched. Helpfull to handle method parameters that can submit a single object or a CGArray of objects.

Name Type Description
object Object
Returns:
Type Description
CGArray

attr(attributes, attributes){CGArray}

Change one or more properties of each element of the CGArray.

my_cgarray.attr(property, value)
my_cgarray.attr( {property1: value1, property2: value2} )
Name Type Description
attributes Property | Value

A property name and the new value.

attributes Object

An object properties and their new values.

Returns:
Type Description
CGArray

each(callback){CGArray}

iterates through each element of the cgarray and run the callback. In the callback this will refer to the element.

.each(function(index, element))

Note: This is slower then a forEach or a for loop directly on the set.

Name Type Description
callback function

Callback run on each element of CGArray. The callback will be called with 2 parameters: the index of the element and the element itself.

Returns:
Type Description
CGArray

empty(){Boolean}

Return true if the CGArray is empty.

Returns:
Type Description
Boolean

get(term){CGArray|or|Element}

Retrieve subset of CGArray or an individual element from CGArray depending on term provided. To find elements by cgvID use Viewer.objects instead.

Term Returns
undefined Full CGArray
Ingeter The element at the index (base-1)
String First element with an 'name' property same as string or undefined
Array CGArray with elements with matching 'name' property
Name Type Description
term Integer | String | Array

The values returned depend on the term (see above table).

Returns:
Type Description
CGArray | or | Element

move(oldIndex, newIndex)

Move the an item from oldIndex to newIndex.

Name Type Description
oldIndex Number

index of element to move

newIndex Number

move element to this index

present(){Boolean}

Returns true if the CGArray is not empty.

Returns:
Type Description
Boolean

Returns new CGArray with element removed

Returns:
Type Description
CGArray

toString(){String}

Return the string 'CGArray'

Returns:
Type Description
String

Return new CGArray with no duplicated values.

Returns:
Type Description
CGArray