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:
const list = new go.List(); // keep a list of GraphObjects
Readonly
countThis read-only property is the length of the List.
Readonly
iteratorGets 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:
const it = aList.iterator;
while (it.next()) {
. . . "index: " + it.key + " value: " + it.value . . .
}
Readonly
iteratorGets 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:
const it = aList.iteratorBackwards;
while (it.next()) {
. . . 'key: ' + it.key + ' value: ' + it.value . . .
}
Readonly
lengthThis read-only property is the length of the List, a synonym for the count property.
Readonly
sizeThis read-only property is the length of the List.
Virtual
allThis 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.
True if all predicate calls are true; false otherwise.
Virtual
anyThis 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.
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.
Virtual
copyVirtual
eachRemoves 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
Sort the List according to a comparison function.
This modified List.
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 ECMAScript iteration, so that functionality has not been made somewhat compatible. These collection classes were defined in GoJS before the ECMAScript collection classes were proposed.