Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/joakimunge/array-nth-last

Tiny library to get last, or nth last entry in array
https://github.com/joakimunge/array-nth-last

array array-helper function javascript npm npm-package package utility

Last synced: about 3 hours ago
JSON representation

Tiny library to get last, or nth last entry in array

Awesome Lists containing this project

README

        

# array-nth-last

Tiny function to get _nth_ last entry from array

## Install

```
$ yarn add array-nth-last
```

or

```
$ npm install array-nth-last --save
```

## Usage

```javascript
const last = require('array-nth-last');

const arr = [1, 2, 3, 4, 5];

last(arr); // => 5
last(arr, 3); // => 2
```

## API

---

### last(array, n?)

Returns the _nth_ last entry from the array

#### array

Type: `Array`

The array from which to get the _nth_ entry

#### n? _optional_

Type: `number`

The desired entry of the array to return