Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 882 Bytes

File metadata and controls

42 lines (32 loc) · 882 Bytes
layout api-command
language Python
permalink api/python/nth/
command nth
related_commands
order_by skip limit [] (bracket) slice, []
order_by/
skip/
limit/
bracket/
slice/

Command syntax

{% apibody %} sequence.nth(index) → object selection.nth(index) → selection<object> {% endapibody %}

Description

Get the nth element of a sequence, counting from zero. If the argument is negative, count from the last element.

Example: Select the second element in the array.

r.expr([1,2,3]).nth(1).run(conn)
r.expr([1,2,3])[1].run(conn)

Example: Select the bronze medalist from the competitors.

r.table('players').order_by(index=r.desc('score')).nth(3).run(conn)

Example: Select the last place competitor.

r.table('players').order_by(index=r.desc('score')).nth(-1).run(conn)