1. array.prototype.concat
ES spec-compliant `Array.prototype.concat` shim/polyfill/replacement that works as far down as ES3.
array.prototype.concat
Package: array.prototype.concat
Created by: es-shims
Last modified: Tue, 19 Mar 2024 17:24:40 GMT
Version: 1.0.6
License: MIT
Downloads: 5,543
Repository: https://github.com/es-shims/Array.prototype.concat

Install

npm install array.prototype.concat
yarn add array.prototype.concat

array.prototype.concat Version Badge

github actions
coverage
dependency status
dev dependency status
License
Downloads

npm badge

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

  • Safari 10 - 13
  • Chrome 48+ (v8 bug)
  • node 6+

Example

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

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

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