There are two possible constructors:
new go.List()
, for JavaScript
new go.List<type>()
for TypeScript, to enforce type checking.
Typical usage would be something like:
var list = new go.List(); // keep a list of GraphObjects
an optional collection of items to add.
This read-only property is the length of the List.
Gets an object that you can use for iterating over the List. The key will be an integer from zero to the count-1. The value will be the item at that index in the list. Typical usage:
var it = aList.iterator;
while (it.next()) {
. . . "index: " + it.key + " value: " + it.value . . .
}
Gets an object that you can use for iterating over the List in backwards order. The key will be an integer from count-1 to zero. The value will be the item at that index in the list. The list is not modified by traversing in reverse order. Typical usage:
var it = aList.iteratorBackwards;
while (it.next()) {
. . . 'key: ' + it.key + ' value: ' + it.value . . .
}
This read-only property is the length of the List, a synonym for the count property.
This read-only property is the length of the List.
Adds a given value to the end of the List.
Be careful not to call this method while iterating over the collection.
This modified List.
This is true if all invocations of the given predicate on items in the collection are true.
Call the given predicate on each item in the collection. As soon as a call returns false, this returns false. Otherwise this returns true. For an empty collection this returns true.
This function must not have any side-effects.
True if all predicate calls are true; false otherwise.
This is true if any invocation of the given predicate on items in the collection is true.
Call the given predicate on each item in the collection. As soon as a call returns true, this returns true. Otherwise this returns false. For an empty collection this returns false.
This function must not have any side-effects.
True if any predicate call is true; false otherwise.
Clears the List. This sets the count to zero.
Be careful not to call this method while iterating over the collection.
Returns whether the given value is in this List.
The value to check.
Whether or not the value is contained within the List.
Makes a shallow copy of this List. The values are not copied, so if they are objects they may continue to be shared with the original List.
The new List with the same elements.
Removes a given value (if found) from the List.
Be careful not to call this method while iterating over the collection.
The value to remove.
true if the value was found and removed, false otherwise.
Call the given function on each item in the collection.
This function must not modify the collection.
This List itself
Returns the element at the given index.
int The index of the element to return.
the value at the given index.
Returns the first item in the list, or null if there is none.
This returns null if there are no items in the list.
Returns the element at the given index.
int The index of the element to return.
the value at the given index.
Returns whether the given value is in this List.
The value to check.
Whether or not the value is contained within the List.
Returns the index of the given value if it is in this List.
The value to check.
int returns -1 if the value is not in this list.
Insert a value before the index i.
Be careful not to call this method while iterating over the collection.
int The index to insert before.
The value to insert.
Returns the last item in the list, or null if these is none.
This returns null if there are no items in the list.
Adds a given value to the end of the List.
Be careful not to call this method while iterating over the collection.
Removes a given value (if found) from the List.
Be careful not to call this method while iterating over the collection.
The value to remove.
true if the value was found and removed, false otherwise.
Removes a value at a given index from the List.
Be careful not to call this method while iterating over the collection.
int The index to remove.
Removes a range of values from the List, given both the starting and the ending zero-based indexes. For example,
list.removeRange(2, 4)
will remove elements 2, 3, and 4 from the list. If there were two or fewer elements in the list to begin with, the list is unchanged. If from is greater than to, the list is unchanged. If from is greater than or equal to the length, the list is unchanged. If to is less than zero, the list is unchanged.
Be careful not to call this method while iterating over the collection.
int The starting index of the range to remove, inclusive; negative values are treated as zero
int The ending index of the range to remove, inclusive; values greater than the length of the list are treated as referring to the last element
This modified List
Reverse the order of items in this List.
This modified List.
Set the element at the given index to a given value.
int The index of the element to set.
The value to set at the index.
Set the element at the given index to a given value.
int The index of the element to set.
The value to set at the index.
Sort the List according to a comparison function.
This function is passed two items in the list. It should return zero if they are equal, less than zero if the first value should come before the second value, or greater than zero if the first value should come after the second value.
This modified List.
Produces a JavaScript Array from the contents of this List.
A copy of the List in Array form.
NOTE: For 2.0 the constructor argument has changed. List now optionally accepts a collection, and only checks types in TypeScript.
An ordered iterable collection. In TypeScript it is a generic class that enforces at compile-time the type of elements that may be added to the List.
An example usage:
You can iterate over the items in a List:
Or:
The key will range from zero to count-1.
For convenience this GoJS List class has synonyms for the following methods and property:
The constructor now takes an optional Iterable or Array argument that provides the initial elements for the new List.
Note that GoJS iteration is quite different than ES6 iteration, so that functionality has not been made somewhat compatible. These collection classes were defined in GoJS before the ES6 collection classes were proposed.