Rakesh Singha
Rakesh Singha

Reputation: 21

Neo4j access array of property to edit

Does anyone know how to access an array property of a node and change the value?

Is there some easy way in cypher like we do in C/C++/Java

array[index] = "some value"

I need to access an array element property of a node and change its value on specific conditions.

Upvotes: 1

Views: 496

Answers (1)

Stefan Armbruster
Stefan Armbruster

Reputation: 39925

For reading the n-th element of an array you can simply use the subscript operator:

return [1,2,3,4,5,6][2]  

gives you the third element of the array, 3 in this case.

If you want to replace e.g. the 4th element of an array with a value of 999, you might use

with [1,2,3,4,5,6] as myarray
return myarray[0..3] + 999 + myarray[4..length(myarray)]

Upvotes: 0

Related Questions