Skip to content

eles.forEach(fn, thisArg?)

eles.forEach — Collection > Iteration and aggregation. Cytoscape.js signatures, parameters and return contract.

eles.forEach — Collection › Iteration and aggregation

Preview · Collection › Iteration and aggregation

Read in the complete API reference · All API members

// Call fn for each element
eles.forEach(fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => void | false, thisArg?: unknown): this

Call 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.

Parameters
NameDescription
fn: ( ele: Collection<NodeData, EdgeData, Data>, i: number, eles: Collection<NodeData, EdgeData, Data>, ) => void | false

( ele, i, eles); return false to stop

thisArg: unknown?

optional receiver for the callback

Returns this

this collection, for chaining

Example

const ids = [];
eles.forEach(ele => ids.push(ele.id()));
console.log(ids.length); // 5

Example graph and handle setup

Also spelled eles.each.