## DuList()

DuList helps manipulating JS Arrays and After Effects Collections the same way. It is faster than converting a Collection to an Array.
Other specific Adobe Lists in other Applications may be supported later.
The first item of a DuList is always at index 0, the last at index length-1.
Accessor is the `DuList.at()` method instead of `Array`.
List length is given by the `DuList.length()` method instead of a property.
DuList does not reimplement methods to add or remove items, use the source list instead with the `DuList.list()` property and the original methods (from the `Collection` instance or `Array`).
DuList can also be used as an iterator with iterator-like methods like `DuList.next()`.
You can also run a function on each item with `DuList.do()`.
Constructor

#### # new DuList()

Constructs a new DuList object

##### Properties:

Name | Type | Description
--- | --- | ---
`isCollection` | `boolean` | true if the original list is an After Effects Collection, false otherwise
`isArray` | `boolean` | true if the original list is an Array, false otherwise

View Source DuAEF_Duik_api.jsxinc, line 1413

# Members

Type: `Boolean`

#### # readonly atEnd

True if the iterator has reached the end.

View Source DuAEF_Duik_api.jsxinc, line 1503

Type: `Boolean`

#### # readonly atStart

True if the iterator is at the start.

View Source DuAEF_Duik_api.jsxinc, line 1495

Type: `int`

#### # readonly current

The current index of the iterator.

View Source DuAEF_Duik_api.jsxinc, line 1487

Type: `Boolean`

#### # readonly isArray

True if the original list is an Array, false otherwise

View Source DuAEF_Duik_api.jsxinc, line 1445

Type: `Boolean`

#### # readonly isCollection

True if the original list is an After Effects Collection, false otherwise.

View Source DuAEF_Duik_api.jsxinc, line 1437

Type: `Array` | `Collection`

#### # readonly list

The original list, an Array or an After Effects Collection.

View Source DuAEF_Duik_api.jsxinc, line 1479

Type: `Boolean`

#### # readonly valid

True if the iterator is between 0 and length-1. Note that on creation, the iterator is always invalid, but calling `DuList.next()` moves it to the beginning and makes it valid.

View Source DuAEF_Duik_api.jsxinc, line 1511

# Methods

#### # static isAECollection(collection) → {boolean}

Checks if the param is an AE collection or an Array

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | `Array` | `Collection` | The list to check

View Source DuAEF_Duik_api.jsxinc, line 15919

Returns:
true if collection is a collection, false if it's an array
Type: `boolean`

#### # static isList(list) → {boolean}

Checks if this is an Array or an After Effects collection type or a `DuList`

##### Parameters:

Name | Type | Description
--- | --- | ---
`list` | `Array` | `Collection` | The list to check

View Source DuAEF_Duik_api.jsxinc, line 2171

Returns:
true if this is a Cllection or an Array or a `DuList`
Type: `boolean`

#### # append()

Alias for `DuList.push()`

View Source DuAEF_Duik_api.jsxinc, line 1912

#### # appendUnique()

Alias for `DuList.pushUnique()`

View Source DuAEF_Duik_api.jsxinc, line 1921

#### # at(index) → {object}

Accessor. First item is always 0, last is always length()-1
Does not move the iterator to the index; to move the iterator use `DuList.goTo` instead.

##### Parameters:

Name | Type | Description
--- | --- | ---
`index` | `int` | The index of the item. If it is out of range (negative or > length()-1), returns null

View Source DuAEF_Duik_api.jsxinc, line 1544

Returns:
The item at the given index.
Type: `object`

#### # concat(other) → {DuList}

Mergeserge two lists.
This method does not change the existing list, but instead returns a new list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`other` | `Array` | `DuList` | The other list.

View Source DuAEF_Duik_api.jsxinc, line 1878

Returns:
The new list.
Type: `DuList`

#### # contains(value, comparisonFunctionopt) → {Boolean}

Checks if the list contains the item

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`value` | `*` |  | The value to find. Must be compatible with the == operand if you don't provide a comparison function
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1592

Returns:
Type: `Boolean`

#### # convertToArray()

Converts the stored list to an Array if it was a Collection.
This enables the modification of the list, but changes in the list will not be reflected in the application (if a layer is removed from the list, it is not removed in the application).

View Source DuAEF_Duik_api.jsxinc, line 1758

#### # count()

Alias for `DuList.length()`

View Source DuAEF_Duik_api.jsxinc, line 1529

#### # do(callBack, reverseopt)

Executes a function on each item of the List

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`callBack` | `function` |  |  | The function to execute, which takes one parameter: an item of the list
`reverse` | `Bool` | <optional> | false | Set this to true to iterate from the end.

View Source DuAEF_Duik_api.jsxinc, line 2133

#### # equals(other, floatPrecisionopt) → {boolean}

Compares two arrays.
The items in the arrays must be compatible with the == operand if you don't provide a comparison function

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`other` | `Array` | `Collection` | `DuList` |  |  | The other list
`floatPrecision` | `int` | <optional> | -1 | The precision for (float) number comparison, number of decimals. Set to -1 to not use.

View Source DuAEF_Duik_api.jsxinc, line 1671

Returns:
true if the two arrays contain the same values
Type: `boolean`

#### # first() → {*}

Gets the first item in the list

View Source DuAEF_Duik_api.jsxinc, line 1749

Returns:
The first item, null if the list is empty.
Type: `*`

#### # getDuplicates() → {DuList}

Returns all duplicated values found in the list

View Source DuAEF_Duik_api.jsxinc, line 1615

Returns:
The duplicated values. An empty list for Ae Collections as they can't have duplicated items.
Type: `DuList`

#### # goTo(index) → {*}

Sets the iterator on the index

##### Parameters:

Name | Type | Description
--- | --- | ---
`index` | `int` | The index

View Source DuAEF_Duik_api.jsxinc, line 2053

Returns:
The item at index, or null if the index is invalid
Type: `*`

#### # goToEnd() → {Object}

Goes to the end of the Iterator

View Source DuAEF_Duik_api.jsxinc, line 2075

Returns:
The item at the end, or null if length is 0
Type: `Object`

#### # goToStart() → {Object}

Goes to the start of the Iterator

View Source DuAEF_Duik_api.jsxinc, line 2084

Returns:
The item at the start, or null if length is 0
Type: `Object`

#### # hasDuplicates() → {boolean}

Checks if the list has duplicated values

View Source DuAEF_Duik_api.jsxinc, line 1601

Returns:
true if the list has duplicated values. Always false for Ae Collections as they can't have duplicated items.
Type: `boolean`

#### # indexOf(value, comparisonFunctionopt) → {int}

Gets the first index of a value, or -1 if not found

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`value` | `*` |  | The value to find. Must be compatible with the == operand if you don't provide a comparison function
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1572

Returns:
The index of the value, -1 if not found
Type: `int`

#### # isEmpty() → {boolean}

Returns true if the list is empty

View Source DuAEF_Duik_api.jsxinc, line 1732

Returns:
Type: `boolean`

#### # join(separator) → {string}

Reimplementation of the `Array.join` function.
For collections, the name of the item will be used, or any other property which makes sense as a string list.

##### Parameters:

Name | Type | Description
--- | --- | ---
`separator` | `string` | The separator to use

View Source DuAEF_Duik_api.jsxinc, line 1971

Returns:
The new length of the list.
Type: `string`

#### # last() → {*}

Gets the last item in the list

View Source DuAEF_Duik_api.jsxinc, line 1740

Returns:
The last item, null if the list is empty.
Type: `*`

#### # length() → {int}

Returns the number of items in the list

View Source DuAEF_Duik_api.jsxinc, line 1525

Returns:
The number of items.
Type: `int`

#### # merge(arr) → {int}

Merges the new array to the current list.
Note that to the contrary of the `Array.concat()` method, this does not create a new list, but modifies the current one in place.
The internal list may be converted to an Array if needed.

##### Parameters:

Name | Type | Description
--- | --- | ---
`arr` | `Array.<any>` | The other array.

View Source DuAEF_Duik_api.jsxinc, line 1937

Returns:
The new length of the list.
Type: `int`

#### # mergeUnique(arr, comparisonFunctionopt) → {int}

Merges the new array to the current list.
Will only add items if they're not already in the list.
Note that to the contrary of the `Array.concat()` method, this does not create a new list, but modifies the current one in place.
The internal list may be converted to an Array if needed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`arr` | `Array.<any>` | `DuList` |  | The other array/list.
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1954

Returns:
The new length of the list.
Type: `int`

#### # next() → {any}

Increments the Iterator
Must be called at least once to validate the iterator

View Source DuAEF_Duik_api.jsxinc, line 2094

Returns:
The next item, or null if there isn't
Type: `any`

#### # pop() → {any|null}

Removes the last element of the list and returns it.
The internal list may be converted to an Array if needed.

View Source DuAEF_Duik_api.jsxinc, line 2034

Returns:
The last element or null if the list is empty.
Type: `any` | `null`

#### # previous() → {Object}

Decrements the Iterator if it's called while valid is false, goes to the end

View Source DuAEF_Duik_api.jsxinc, line 2114

Returns:
The previous item, or null if there isn't
Type: `Object`

#### # push(element0, element1, elementN) → {int}

Adds one or more elements to the end of the list and returns the new length of the list.
The internal list may be converted to an Array if needed.

##### Parameters:

Name | Type | Description
--- | --- | ---
`element0` | `any` | The element(s) to add to the end of the array.
`element1` | `any` | The element(s) to add to the end of the array.
`element...` | `any` | The element(s) to add to the end of the array.
`elementN` | `any` | The element(s) to add to the end of the array.

View Source DuAEF_Duik_api.jsxinc, line 1862

Returns:
The new length of the list.
Type: `int`

#### # pushUnique(comparisonFunctionopt, element0, element1, elementN) → {int}

Adds one or more elements to the end of the list and returns the new length of the list, only if the value is not already in the list
The internal list may be converted to an Array if needed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.
`element0` | `any` |  | The element(s) to add to the end of the array.
`element1` | `any` |  | The element(s) to add to the end of the array.
`element...` | `any` |  | The element(s) to add to the end of the array.
`elementN` | `any` |  | The element(s) to add to the end of the array.

View Source DuAEF_Duik_api.jsxinc, line 1898

Returns:
The new length of the list.
Type: `int`

#### # reinitIterator()

Reinits the iterator, i.e. go to index -1 so that the next call to `DuList.next` returns the first item.

View Source DuAEF_Duik_api.jsxinc, line 2044

#### # remove(index)

Removes the item at the given index. The internal list may be converted to an Array if needed.
The iterator invalidated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`index` | `int` | The index.

View Source DuAEF_Duik_api.jsxinc, line 1779

#### # removeAll(index, comparisonFunctionopt) → {int}

Removes all occurences of the value from the list. The value must be checkable with the `==` operator if no `comparisonFunction` is provided.
The internal list may be converted to an Array if needed.
The iterator invalidated.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`index` | `int` |  | The index.
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1814

Returns:
The number of items removed.
Type: `int`

#### # removeDuplicates(comparisonFunctionopt) → {Array}

Removes all duplicated values from the list, and returns them.
The internal list may be converted to an Array if needed.
The iterator invalidated.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1640

Returns:
The duplicated (and removed) values. An empty list for Ae Collections as they can't have duplicated items.
Type: `Array`

#### # removeOne(index, comparisonFunctionopt)

Removes the first value from the list. The value must be checkable with the `==` operator if no `comparisonFunction` is provided.
The internal list may be converted to an Array if needed.
The iterator invalidated.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`index` | `int` |  | The index.
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 1795

#### # replace(what, with, comparisonFunctionopt) → {int}

Replaces all occurences of a value with another value.
The internal list may be converted to an Array if needed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`what` | `any` |  | The current value
`with` | `any` |  | The new value
`comparisonFunction` | `function` | <optional> | A function which compares two values which returns true if the values are considered the same.

View Source DuAEF_Duik_api.jsxinc, line 2009

Returns:
The number of occurences which were updated.
Type: `int`

#### # sort(compareFunction) → {Array}

Reimplements the Array.sort() method.
The internal list may be converted to an Array if needed.
The iterator is invalidated.

##### Parameters:

Name | Type | Description
--- | --- | ---
`compareFunction` | `function` | Specifies a function that defines the sort order. If omitted, the array elements are converted to strings, then sorted according to each character's Unicode code point value.

View Source DuAEF_Duik_api.jsxinc, line 1840

Returns:
The sorted array. Note that the array is sorted in place, and no copy is made.
Type: `Array`