Example 1 — Official Samples
The first item of an array, the first character of a string, and an empty array — straight from the Ramda docs.
console.log(R.head(['fi', 'fo', 'fum'])); // fi
console.log(R.head('abc')); // a
console.log(R.head([])); // undefined How It Works
- Array. Index
0of['fi', 'fo', 'fum']is'fi'. - String. A string is read like a list of characters, so the first one is
'a'. - Empty.
[]has no index0, soR.headreturnsundefinedinstead of throwing. - Read-only. None of the inputs is changed.
