// 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 |
Returns
thisthis collection, for chaining
Example
const ids = [];eles.forEach(ele => ids.push(ele.id()));console.log(ids.length); // 5Also spelled eles.each.