Example 1 — Official: Second, Last, and Out of Range
The three array samples from the Ramda docs.
const list = ["foo", "bar", "baz", "quux"];
console.log(R.nth(1, list)); // → bar
console.log(R.nth(-1, list)); // → quux
console.log(R.nth(-99, list)); // → undefined How It Works
- Index 1. Indexes start at
0, so1is the second item,"bar". - Index -1. Becomes
4 - 1 = 3, the last slot,"quux". - Index -99. Becomes
-95; nothing lives there, so you getundefined.
