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.
Written by Codi
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#