Socket
Socket
Sign inDemoInstall

array.prototype.findlastindex

Package Overview
Dependencies
66
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    array.prototype.findlastindex

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


Version published
Weekly downloads
13M
decreased by-0.44%
Maintainers
1
Install size
3.62 MB
Created
Weekly downloads
 

Package description

What is array.prototype.findlastindex?

The array.prototype.findlastindex npm package extends the Array prototype to include a findLastIndex method. This method allows you to search an array backwards and find the index of the last element that satisfies a provided testing function. It is particularly useful for finding the last occurrence of elements in arrays where elements may not be unique or when the order of elements is significant.

What are array.prototype.findlastindex's main functionalities?

Finding the last index of an element that satisfies a condition

This feature allows you to find the index of the last element in an array that meets a specific condition. In the provided code sample, the condition is that the element must be greater than 13, which would return 4, the index of 44, as it is the last element satisfying the condition.

[5, 12, 8, 130, 44].findLastIndex(element => element > 13)

Other packages similar to array.prototype.findlastindex

Changelog

Source

v1.2.5 - 2024-03-19

Commits

  • [meta] remove useless ESM 4ed36ab
  • [Deps] update call-bind, es-abstract a6e3816
  • [Refactor] use es-object-atoms where possible 3fbee9b
  • [Dev Deps] update hasown, tape dc6356c

Readme

Source

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

Keywords

FAQs

Last updated on 19 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc