Return the first element in an array. Is well tested...
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Return the first element in an array. Is tested.


The module can be used when you need a function that returns the first element of an array


npm i first-of-array --save-dev


Simply require the first-of-array module. The export function can be used in any module you desire:

const first = require('first-of-array');

first([1,100,1000); // 1
first([['Ahad', 12, 10000], 12, 'Three', true]); // ['Ahad', 12, 10000]


  • add more tests


npm test

Also supports the standards JavaScript library, configure as follows:

"standard": {
    "ignore": [
first([1,2,3,4,5]);                  // ==> returns a number
first([['Ahad',2,3,4,5]);            // ==> returns a string
first([[1,2e10],2,3,4,5])            // ==> returns only the first element
first([[true, false], 'id', 1004]);  // ==> returns the first element, even if is array
first([]);                           // ==> returns undefined, if passed empty array

##Related Modules


Feel free to file an issue or bug.