# LINDEX

> Get the element at an index of a list.

URL: https://docs.hotkv.com/commands/lindex/

```
LINDEX key index
```

- Group: List
- Complexity: O(N) where N is the distance of the index from the nearer end
- HotKV Cloud: all plans
- On-Premise: no license needed

`LINDEX` returns the element at position `index` of the list stored at `key`.
Indexes start at `0`; negative indexes count from the end, so `-1` is the last
element.

## Return value

| Case | RESP2 | RESP3 |
| --- | --- | --- |
| Index in range | Bulk string: the element | Same |
| Index out of range, or key does not exist | Nil bulk string | Null |

Errors:

- `WRONGTYPE` if `key` holds a value that is not a list.
- `ERR value is not an integer or out of range` if `index` is not an integer.
  The key is looked up first, so a missing key replies nil even for a bad
  index.

## Examples

```
127.0.0.1:6379> RPUSH letters a b c
(integer) 3
127.0.0.1:6379> LINDEX letters 0
"a"
127.0.0.1:6379> LINDEX letters -1
"c"
127.0.0.1:6379> LINDEX letters 5
(nil)
```

## Compatibility

Same as Redis 7.4 and Valkey 8.

## See also

[LSET](https://docs.hotkv.com/commands/lset/index.md), [LRANGE](https://docs.hotkv.com/commands/lrange/index.md), [LPOS](https://docs.hotkv.com/commands/lpos/index.md),
[LLEN](https://docs.hotkv.com/commands/llen/index.md)