#eles.size()
// The number of elements — the method form of length
eles.size(): numberThe number of elements — the method form of length.
numberthe element count
Visit, map, reduce and aggregate elements in collection order.
eles.size()// The number of elements — the method form of length
eles.size(): numberThe number of elements — the method form of length.
numberthe element count
eles.empty()// Whether the collection holds no elements
eles.empty(): booleanWhether the collection holds no elements.
booleantrue when empty
eles.nonempty()// Whether the collection holds at least one element
eles.nonempty(): booleanWhether the collection holds at least one element.
booleantrue when non-empty
eles.forEach(fn, thisArg?)// Call fn for each element
eles.forEach(fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => void | false, thisArg?: unknown): thisCall fn for each element. Returning false from the callback stops the iteration early.
With no thisArg the callback is plain-called, so this is undefined inside it — the callback receives each element as its first argument.
| Name | Description |
|---|---|
fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => void | false |
|
thisArg: unknown? | optional receiver for the callback |
thisthis collection, for chaining
Example
const ids = [];eles.forEach(ele => ids.push(ele.id()));console.log(ids.length); // 5Also spelled eles.each.
eles.toArray()// The elements as a plain array of length-1 collections
eles.toArray(): Collection<NodeData, EdgeData, Data>[]The elements as a plain array of length-1 collections.
Collection<NodeData, EdgeData, Data>[]a new array of the members
Example
console.log(eles.toArray().map(ele => ele.id())); // ['a', 'b', 'c', 'ab', 'bc']eles.slice(start?, end?)// A sub-range of the collection, with Array#slice semantics (negative indices count from the end)
eles.slice(start?: number, end?: number): Collection<NodeData, EdgeData, Data>A sub-range of the collection, with Array#slice semantics (negative indices count from the end).
| Name | Description |
|---|---|
start: number?Default: 0 | first index, inclusive |
end: number?Default: this.length | last index, exclusive |
Collection<NodeData, EdgeData, Data>the sub-range as a new collection
Example
console.log(eles.slice().map(ele => ele.id())); // ["a","b","c","ab","bc"]eles.sort(sortFn)// A copy sorted by a comparator
eles.sort(sortFn: ( a: Collection<NodeData, EdgeData, Data>, b: Collection<NodeData, EdgeData, Data>, ) => number): Collection<NodeData, EdgeData, Data>A copy sorted by a comparator. Note that sort order is a property of the collection, not of drawing: draw order is structural and there is no z-index.
| Name | Description |
|---|---|
sortFn: ( a: Collection<NodeData, EdgeData, Data>, b: Collection<NodeData, EdgeData, Data>, ) => number |
|
Collection<NodeData, EdgeData, Data>a new, sorted collection
Example
const sorted = eles.sort((a, b) => a.id().localeCompare(b.id()));console.log(sorted.first().id()); // 'a'eles.eq(i)// The element at an index, as a length-1 collection
eles.eq(i: number): Collection<NodeData, EdgeData, Data>The element at an index, as a length-1 collection.
| Name | Description |
|---|---|
i: number | the index |
Collection<NodeData, EdgeData, Data>that element, or an empty collection when out of range
eles.first()// The first element, as a length-1 collection
eles.first(): Collection<NodeData, EdgeData, Data>The first element, as a length-1 collection.
Collection<NodeData, EdgeData, Data>the first element, or an empty collection
eles.last()// The last element, as a length-1 collection
eles.last(): Collection<NodeData, EdgeData, Data>The last element, as a length-1 collection.
Collection<NodeData, EdgeData, Data>the last element, or an empty collection
eles.map(fn, thisArg?)// Map each element through fn into a plain array
eles.map<T>(fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T, thisArg?: unknown): T[]Map each element through fn into a plain array.
| Name | Description |
|---|---|
fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T |
|
thisArg: unknown? | optional receiver for the callback |
T[]an array of the results
Example
console.log(cy.nodes().map(node => node.id())); // ['a', 'b', 'c']eles.some(fn, thisArg?)// Whether any element satisfies the predicate
eles.some(fn: EleFilterFn<NodeData, EdgeData, Data>, thisArg?: unknown): booleanWhether any element satisfies the predicate. Short-circuits.
| Name | Description |
|---|---|
fn: EleFilterFn<NodeData, EdgeData, Data> |
|
thisArg: unknown? | optional receiver for the callback |
booleantrue when at least one element matches
eles.every(fn, thisArg?)// Whether every element satisfies the predicate
eles.every(fn: EleFilterFn<NodeData, EdgeData, Data>, thisArg?: unknown): booleanWhether every element satisfies the predicate. Short-circuits, and is vacuously true for an empty collection.
| Name | Description |
|---|---|
fn: EleFilterFn<NodeData, EdgeData, Data> |
|
thisArg: unknown? | optional receiver for the callback |
booleantrue when all elements match
eles.reduce(fn, initial)// Fold the collection into a single value
eles.reduce<T>(fn: ( acc: T, ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T, initial: T): TFold the collection into a single value.
| Name | Description |
|---|---|
fn: ( acc: T, ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => T |
|
initial: T | the starting accumulator (required, unlike |
Tthe final accumulator
Example
const count = eles.reduce((sum, ele) => sum + (ele.isNode() ? 1 : 0), 0);console.log(count); // 3eles.max(valFn, thisArg?)// The element maximizing valFn, with its value
eles.max(valFn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => number, thisArg?: unknown): { value: number; ele: Collection<NodeData, EdgeData, Data> | undefined }The element maximizing valFn, with its value.
| Name | Description |
|---|---|
valFn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => number |
|
thisArg: unknown? | optional receiver for the callback |
{ value: number; ele: Collection<NodeData, EdgeData, Data> | undefined }{ value, ele }, or { value: -Infinity, ele: undefined } when the collection is empty
Example
const result = cy.nodes().max(node => node.data('score'));console.log(result.value); // 3eles.min(valFn, thisArg?)// The element minimizing valFn, with its value
eles.min(valFn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => number, thisArg?: unknown): { value: number; ele: Collection<NodeData, EdgeData, Data> | undefined }The element minimizing valFn, with its value.
| Name | Description |
|---|---|
valFn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => number |
|
thisArg: unknown? | optional receiver for the callback |
{ value: number; ele: Collection<NodeData, EdgeData, Data> | undefined }{ value, ele }, or { value: Infinity, ele: undefined } when the collection is empty
Example
const result = cy.nodes().min(node => node.data('score'));console.log(result.value); // 1