Last Updated: May 28, 2017
·
1.163K
· Codi

How to get the first element of an array in Javascript - example

You can use this array-first open source component to to return the first element of any given array in Javascript.

Examples:

` first([1, 2, 3]) // => 1

first(['a', 'b', 'c']) // => 'a' `

If the array is empty, it will return null.

It also has 2 tests.