Skip to content

Metadata and identity

Inspect identity and collection membership.

#eles.length

// How many elements this collection holds
eles.length: number

How many elements this collection holds.

Returns number

Example

console.log(eles.length); // 5

Example graph and handle setup

#eles.cy()

// The core this collection belongs to
eles.cy(): Core<NodeData, EdgeData>

The core this collection belongs to.

Returns Core<NodeData, EdgeData>

the instance that owns these elements — a collection cannot span two cores, so this is also the identity a set operation against a foreign collection would violate

Example

console.log(eles.cy() === cy); // true

Example graph and handle setup

#eles.collection()

// Create an empty collection bound to the same core
eles.collection(): Collection<NodeData, EdgeData, Data>

Create an empty collection bound to the same core. Takes no arguments. Use union() to build a set from existing elements, or filter() to select members of this collection.

Returns Collection<NodeData, EdgeData, Data>

a fresh empty collection bound to this core — the seed for building a set up by union

Example

console.log(eles.collection().map(ele => ele.id())); // []

Example graph and handle setup

Throws

if called with any argument — use cy.add() to insert definitions or set operations to build collections

#eles.hasElementWithId(id)

// Whether this collection contains an element with the given id
eles.hasElementWithId(id: string): boolean

Whether this collection contains an element with the given id.

Parameters
NameDescription
id: string

the element id

Returns boolean

true when a member has that id

Example

console.log(eles.hasElementWithId('a')); // true

Example graph and handle setup

#eles.indexOf(ele)

// Index of an element within this collection
eles.indexOf(ele: Collection): number

Index of an element within this collection.

Parameters
NameDescription
ele: Collection

the element to find; only its first element is used

Returns number

the index, or -1 when it is not in this collection

Example

console.log(eles.indexOf(cy.getElementById('a'))); // 0

Example graph and handle setup

#eles.indexOfId(id)

// Position of the element with this id within the collection
eles.indexOfId(id: string): number

Position of the element with this id within the collection.

Parameters
NameDescription
id: string

the element id

Returns number

the index, or -1 when absent

Example

console.log(eles.indexOfId('a')); // 0

Example graph and handle setup

#ele.id()

// The first element's id
ele.id(): string | undefined

The first element's id. Cached on the handle, so it stays readable after the element is removed.

Returns string | undefined

the id, or undefined when the collection is empty

Example

console.log(eles.id()); // "a"

Example graph and handle setup

#ele.group()

// The first element's group
ele.group(): GroupName | undefined

The first element's group. Cached on the handle, so it stays readable after removal.

Returns GroupName | undefined

'nodes' or 'edges', or undefined when empty

Example

console.log(eles.group()); // "nodes"

Example graph and handle setup

#ele.json()

// Plain-object form of the first element (undefined when empty)
ele.json(): Record<string, unknown> | undefined

Plain-object form of the first element (undefined when empty).

Returns Record<string, unknown> | undefined

the definition-form object for the first element, or undefined when the collection is empty; it round-trips through cy.add(), which is the supported restore path because cy.json() is export-only

Example

console.log(cy.getElementById('a').json().data.id); // 'a'

Example graph and handle setup

#eles.jsons()

// Plain-object form of every element
eles.jsons(): (Record<string, unknown> | undefined)[]

Plain-object form of every element.

Returns (Record<string, unknown> | undefined)[]

one object per element, in collection order — the plural of json(), not a graph-level export

Example

console.log(eles.jsons().map(def => def.data.id)); // ['a', 'b', 'c', 'ab', 'bc']

Example graph and handle setup

#ele.isNode()

// Whether the first element is a node
ele.isNode(): boolean

Whether the first element is a node.

Returns boolean

true for a node

Example

console.log(eles.isNode()); // true

Example graph and handle setup

#ele.isEdge()

// Whether the first element is an edge
ele.isEdge(): boolean

Whether the first element is an edge.

Returns boolean

true for an edge

Example

console.log(eles.isEdge()); // false

Example graph and handle setup

#ele.isLoop()

// Whether the first element is a self-loop — an edge whose source and target are the same node
ele.isLoop(): boolean

Whether the first element is a self-loop — an edge whose source and target are the same node.

Returns boolean

true for a loop edge; false for nodes and removed elements

Example

console.log(eles.isLoop()); // false

Example graph and handle setup

#ele.isSimple()

// Whether the first element is a non-loop edge
ele.isSimple(): boolean

Whether the first element is a non-loop edge.

Returns boolean

true for an edge between two distinct nodes

Example

console.log(eles.isSimple()); // false

Example graph and handle setup

#ele.removed()

// Whether the first element has been removed from the graph
ele.removed(): boolean

Whether the first element has been removed from the graph. A removed element's handle stays usable — reads are no-ops or undefined, and the cached id()/group() remain readable.

Returns boolean

true when the element is no longer in the graph

Example

console.log(eles.removed()); // false

Example graph and handle setup

#ele.inside()

// Whether the first element is still in the graph — the complement of removed()
ele.inside(): boolean

Whether the first element is still in the graph — the complement of removed().

Returns boolean

true when the element is live

Example

console.log(eles.inside()); // true

Example graph and handle setup

All guides · Alphabetical API index · Read continuously