apoc.coll.insert

Details

Syntax

apoc.coll.insert(coll, index, value)

Description

Inserts a value into the specified index in the LIST<ANY>.

Arguments

Name

Type

Description

coll

LIST<ANY>

The list to insert a value into.

index

INTEGER

The position in the list to insert the given value.

value

ANY

The value to be inserted.

Returns

LIST<ANY>

Usage examples

The following examples insert the value 11 at index 3 in the list using both APOC and Cypher:

apoc.coll.insert
WITH [1,3,5,7,9] AS originalList, 3 AS index, 11 AS itemToInsert
RETURN apoc.coll.insert(originalList, index, itemToInsert) AS output;
Using Cypher’s list concatenation
WITH [1,3,5,7,9] AS originalList, 3 AS index, 11 AS itemToInsert
RETURN originalList[0..index] + itemToInsert + originalList[index..] AS output
Results
Output

[1, 3, 5, 11, 7, 9]