1. array.prototype.findlastindex
An ESnext spec-compliant `Array.prototype.findLastIndex` shim/polyfill/replacement that works as far down as ES3.
array.prototype.findlastindex
Package: array.prototype.findlastindex
Created by: es-shims
Last modified: Tue, 19 Mar 2024 17:22:15 GMT
Version: 1.2.5
License: MIT
Downloads: 53,523,520
Repository: https://github.com/es-shims/Array.prototype.findLastIndex

Install

npm install array.prototype.findlastindex
yarn add array.prototype.findlastindex

array.prototype.findlastindex Version Badge

github actions
coverage
dependency status
dev dependency status
License
Downloads

npm badge

An ESnext spec-compliant Array.prototype.findLastIndex shim/polyfill/replacement that works as far down as ES3.

This package implements the es-shim API interface. It works in an ES3-supported environment and complies with the proposed spec.

Because Array.prototype.findLastIndex depends on a receiver (the this value), the main export takes the array to operate on as the first argument.

Getting started

 npm install --save array.prototype.findlastindex

Usage/Examples

 var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');

var arr = [1, [2], [], 3, [[4]]];
var isNumber = function (x) { return typeof x === 'number' };

assert.deepEqual(findLastIndex(arr, isNumber), 3);
 var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');
/* when Array#findLastIndex is not present */
delete Array.prototype.findLastIndex;
var shimmed = findLastIndex.shim();

assert.equal(shimmed, findLastIndex.getPolyfill());
assert.deepEqual(arr.findLastIndex(isNumber), findLastIndex(arr, isNumber));
 var findLastIndex = require('array.prototype.findlastindex');
var assert = require('assert');
/* when Array#findLastIndex is present */
var shimmed = findLastIndex.shim();

assert.equal(shimmed, Array.prototype.findLastIndex);
assert.deepEqual(arr.findLastIndex(isNumber), findLastIndex(arr, isNumber));

Tests

Simply clone the repo, npm install, and run npm test

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code