Socket
Book a DemoInstallSign in
Socket

array.prototype.push

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array.prototype.push

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

latest
Source
npmnpm
Version
1.0.7
Version published
Weekly downloads
3.5K
-14.34%
Maintainers
1
Weekly downloads
 
Created
Source

array.prototype.push Version Badge

github actions coverage dependency status dev dependency status License Downloads

npm badge

An ES spec-compliant Array.prototype.push 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 spec.

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

Engines where this is needed

Note: this list is not exhaustive.

  • in node/chrome (including node 18-19): push fails to throw on a nonwritable length property
  • IE 8 and below, and pre-ES6 engines: deleteCount isn't defaulted to length - start until ES6
  • Safari 5.0: sometimes it returns undefined
  • Safari 7/8: sparse arrays of size 1e5 or greater break
  • Opera 12.15: breaks on small sparse arrays

Example

var push = require('array.prototype.push');
var assert = require('assert');

var a = [1, 1, 1];
assert.equal(push(a, 1, 2), 5);
assert.deepEqual(a, [1, 1, 1, 1, 2]);
var push = require('array.prototype.push');
var assert = require('assert');
/* when Array#push is not present */
delete Array.prototype.push;
var shimmed = push.shim();
assert.equal(shimmed, push.getPolyfill());
assert.equal(shimmed, Array.prototype.push);
var a = [1, 2, 3];
var b = [1, 2, 3];
assert.equal(a.push(1, 2, 3), push(b, 1, 2, 3));
assert.deepEqual(a, b);
var push = require('array.prototype.push');
var assert = require('assert');
/* when Array#push is present */
var shimmed = push.shim();
assert.equal(shimmed, Array.prototype.push);
assert.deepEqual([1, 2, 3].push(1, 2, 3), push([1, 2, 3], 1, 2, 3));

Tests

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

Keywords

Array.prototype.push

FAQs

Package last updated on 14 Mar 2025

Did you know?

Socket

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