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 nullHere, we use the or else operator to return null if the cart is empty. Otherwise, the query would fail with an error.