or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-isarray

Array#isArray polyfill for older browsers and deprecated Node.js versions

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/isarray@2.0.x

To install, run

npx @tessl/cli install tessl/npm-isarray@2.0.0

index.mddocs/

isarray

A lightweight polyfill that provides Array.isArray functionality for older browsers and deprecated Node.js versions. Uses native Array.isArray when available, falls back to Object.prototype.toString.call() method when not available.

Package Information

  • Package Name: isarray
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install isarray

Core Imports

var isArray = require('isarray');

For ES modules (CommonJS interop):

import isArray from 'isarray';

Basic Usage

var isArray = require('isarray');

console.log(isArray([])); // => true
console.log(isArray({})); // => false
console.log(isArray(null)); // => false
console.log(isArray('[]')); // => false

// Works with arrays that have additional properties
var arr = [];
arr.foo = 'bar';
console.log(isArray(arr)); // => true

// Returns false for array-like objects
var obj = {};
obj[0] = true;
console.log(isArray(obj)); // => false

Capabilities

Array Detection

Determines whether the passed value is an Array.

/**
 * Determines whether the passed value is an Array
 * @param {*} arr - The value to be checked
 * @returns {boolean} Returns true if the value is an Array, false otherwise
 */
function isArray(arr);

Parameters:

  • arr (any): The value to be checked

Returns:

  • boolean: Returns true if the value is an Array, false otherwise

Implementation Details:

  • Uses native Array.isArray when available (modern environments)
  • Falls back to Object.prototype.toString.call(arr) == '[object Array]' for older environments
  • Works consistently across both native and polyfill implementations
  • Handles edge cases like arrays with additional properties correctly

Browser Compatibility:

  • Internet Explorer 8+
  • Firefox 17+
  • Chrome 22+
  • Opera 12+
  • Safari 5.1+
  • Mobile browsers (iOS 6.0+, Android 4.2+)

Usage Examples:

var isArray = require('isarray');

// Basic type checking
console.log(isArray([])); // => true
console.log(isArray([1, 2, 3])); // => true
console.log(isArray({})); // => false
console.log(isArray(null)); // => false
console.log(isArray(undefined)); // => false
console.log(isArray('string')); // => false
console.log(isArray(42)); // => false
console.log(isArray(function(){})); // => false

// Edge cases
console.log(isArray('[]')); // => false (string, not array)
console.log(isArray(document.querySelectorAll('div'))); // => false (NodeList, not array)

// Arrays with properties
var arr = [1, 2, 3];
arr.customProperty = 'value';
console.log(isArray(arr)); // => true

// Array-like objects
var arrayLike = { 0: 'a', 1: 'b', length: 2 };
console.log(isArray(arrayLike)); // => false

Migration Note

For modern environments: The documentation explicitly recommends using native Array.isArray directly instead of this polyfill when targeting modern browsers and Node.js versions that support it natively.

// Modern approach (when IE8 support not needed)
console.log(Array.isArray([])); // => true

// Polyfill approach (for IE8 and older Node.js versions)
var isArray = require('isarray');
console.log(isArray([])); // => true