Last Updated: May 28, 2017
·
1.675K
· 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.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
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