Array#isArray polyfill for older browsers and deprecated Node.js versions
npx @tessl/cli install tessl/npm-isarray@2.0.0A 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.
npm install isarrayvar isArray = require('isarray');For ES modules (CommonJS interop):
import isArray from 'isarray';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)); // => falseDetermines 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 checkedReturns:
boolean: Returns true if the value is an Array, false otherwiseImplementation Details:
Array.isArray when available (modern environments)Object.prototype.toString.call(arr) == '[object Array]' for older environmentsBrowser Compatibility:
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)); // => falseFor 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