Skip to main content

Overview

Returns the element at index index in the list stored at key. The index is zero-based. Negative indices can be used to designate elements starting from the tail of the list.

Method Signature

Parameters

key
string
required
The key of the list.
index
number
required
The index of the element to retrieve (zero-based). Negative indices count from the end of the list (e.g., -1 is the last element, -2 is the second-to-last).

Return Value

element
TData | null
The element at the specified index, or null if the index is out of range or the list does not exist.

Examples

Basic Usage

Using Negative Indexes

Working with Objects

Peek at Queue Elements

Accessing List Elements

Error Handling

Iterating Through a List

See Also

  • LSET - Set the value of an element by index
  • LRANGE - Get a range of elements from a list
  • LLEN - Get the length of a list
  • LPUSH - Insert elements at the head of a list