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
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#