Ordinal selector
Learn how to get an item by its position in the list.
The ordinal selector allows you to access an element at a specific position in a list using its ordinal number instead of its index or key.
So can I finally count like a human?
That's right! With the ordinal selector, you can use natural counting, starting at 1, instead of the typical 0-based indexing in programming.
For example, to access the second item in a list, you can simply use:
let transport = ["🚀", "🚗", "🚆"];transport[2nd] // 🚗
For a real-world example, let's say you want to access the second item added to a shopping cart:
cart.items[2nd] or else null
Here, we use the or else operator to return null if the cart is empty. Otherwise, the query would fail with an error.