Socket
Socket
Sign inDemoInstall

array.prototype.findlast

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.findlast

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


Version published
Maintainers
1
Install size
3.62 MB
Created

Package description

What is array.prototype.findlast?

The array.prototype.findlast npm package extends the Array prototype to include a `findLast` method. This method allows users to search through an array from the end towards the beginning, returning the last element that satisfies a provided testing function. It is particularly useful for finding the last occurrence of elements in an array that meet certain criteria.

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

Finding the last element that meets a condition

This feature allows you to find the last element in an array that meets a specific condition. In the provided code sample, `findLast` is used to find the last even number in the array.

[1, 2, 3, 4, 5].findLast(element => element % 2 === 0)

Other packages similar to array.prototype.findlast

Changelog

Source

v1.2.5 - 2024-03-19

Commits

  • [meta] remove useless ESM 30b3843
  • [Deps] update call-bind, es-abstract f339e4d
  • [actions] remove redundant finisher 3b66016
  • [Refactor] use es-object-atoms where possible c7146f1
  • [Dev Deps] update hasown, tape 16149a0

Readme

Source

array.prototype.findlast Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ESnext spec-compliant Array.prototype.findLast 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.findLast 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.findlast

Usage/Examples

var findLast = require('array.prototype.findlast');
var assert = require('assert');

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

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

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

assert.equal(shimmed, Array.prototype.findLast);
assert.deepEqual(arr.findLast(isNumber), findLast(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