nth
ReQL command: nth
Command syntax
sequence.nth(index) → object selection.nth(index) → selection<object>
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)
Related commands
Get more help
Couldn't find what you were looking for?
- Ask a question on Stack Overflow
- Chat with us and our community on Slack
- Talk to the team on IRC on #rethinkdb@freenode.net — via Webchat
- Ping @rethinkdb on Twitter
- Post an issue on the documentation issue tracker on GitHub
© RethinkDB contributors
Licensed under the Creative Commons Attribution-ShareAlike 3.0 Unported License.
https://rethinkdb.com/api/python/nth/