Skip to content

Add findLast and findLastIndex to Array.prototype. The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. The findLast() method returns the value of the last element in the provided array that satisfies the p…

Notifications You must be signed in to change notification settings

felixdrp/array-find-last

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

array-find-last

Add findLast and findLastIndex to Array.prototype. The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. The findLast() method returns the value of the last element in the provided array that satisfies the provided testing function. If no values satisfies the testing function, undefined is returned.

Install

npm install array-find-last

Use

# es6
import 'array-find-last';
require('array-find-last');

Example

import 'array-find-last';

const array1 = [5, 12, 8, 130, 44];

const foundLast = array1.findLast(element => element > 10);

const foundLastIndex = array1.findLastIndex(element => element > 10);

console.log(foundLast);
// expected output: 44

console.log(foundLastIndex);
// expected output: 4

About

Add findLast and findLastIndex to Array.prototype. The findLastIndex() method returns the index of the last element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test. The findLast() method returns the value of the last element in the provided array that satisfies the p…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published