Cypher Last Function

last() returns the last element in a list.

Syntax: last(expression)

Returns: The type of the value returned will be that of the last element of list.

Arguments

NameDescription
listAn expression that returns a list.

Example

RETURN last([4, 3, 7, null, 2])

The value returned will be the last element among all the expressions in the list passed to the function, which in this case will be 2.

Considerations

  • last(null) returns null.
  • If the first element in list is nulllast(list) will return null.
  • last([]) returns null.

Example

RETURN last([2, null, "Hello, World!", true, -1, 2020])

Returns the following Result

last([2, null, "Hello, World!", true, -1, 2020])
2020

Example

RETURN last([true, -1, 2020, 2, "Hello, World!"])

Returns the following Result

last([true, -1, 2020, 2, "Hello, World!"]))
"Hello, World!"

Example

RETURN last([-1, 2020, 2, "Hello, World!", true])

Returns the following Result

last([-1, 2020, 2, "Hello, World!", true])
true

Example

RETURN last([true, -1, 2020, 2, "Hello, World!", null])

Returns the following Result

last([true, -1, 2020, 2, "Hello, World!", null])
null

Example

RETURN last(["Hello, World!"])

Returns the following Result

last(["Hello, World!"])
"Hello, World!"

Example

WITH [true, "Hi", null, 7, 17, false, 2020] as list
RETURN last(list)

Returns the following Result

last(list)
2020

Example

WITH [false] as list
RETURN last(list)

Returns the following Result

last(list)
false

Example

RETURN last([])

Returns the following Result

last([])
null

Example

WITH [] as list
RETURN last(list)

Returns the following Result

last(list)
null

Example

RETURN last(null)

Returns the following Result

last(null)
null

Learn More