or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# isarray

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: isarray

7

- **Package Type**: npm

8

- **Language**: JavaScript

9

- **Installation**: `npm install isarray`

10

11

## Core Imports

12

13

```javascript

14

var isArray = require('isarray');

15

```

16

17

For ES modules (CommonJS interop):

18

19

```javascript

20

import isArray from 'isarray';

21

```

22

23

## Basic Usage

24

25

```javascript

26

var isArray = require('isarray');

27

28

console.log(isArray([])); // => true

29

console.log(isArray({})); // => false

30

console.log(isArray(null)); // => false

31

console.log(isArray('[]')); // => false

32

33

// Works with arrays that have additional properties

34

var arr = [];

35

arr.foo = 'bar';

36

console.log(isArray(arr)); // => true

37

38

// Returns false for array-like objects

39

var obj = {};

40

obj[0] = true;

41

console.log(isArray(obj)); // => false

42

```

43

44

## Capabilities

45

46

### Array Detection

47

48

Determines whether the passed value is an Array.

49

50

```javascript { .api }

51

/**

52

* Determines whether the passed value is an Array

53

* @param {*} arr - The value to be checked

54

* @returns {boolean} Returns true if the value is an Array, false otherwise

55

*/

56

function isArray(arr);

57

```

58

59

**Parameters:**

60

- `arr` (any): The value to be checked

61

62

**Returns:**

63

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

64

65

**Implementation Details:**

66

- Uses native `Array.isArray` when available (modern environments)

67

- Falls back to `Object.prototype.toString.call(arr) == '[object Array]'` for older environments

68

- Works consistently across both native and polyfill implementations

69

- Handles edge cases like arrays with additional properties correctly

70

71

**Browser Compatibility:**

72

- Internet Explorer 8+

73

- Firefox 17+

74

- Chrome 22+

75

- Opera 12+

76

- Safari 5.1+

77

- Mobile browsers (iOS 6.0+, Android 4.2+)

78

79

**Usage Examples:**

80

81

```javascript

82

var isArray = require('isarray');

83

84

// Basic type checking

85

console.log(isArray([])); // => true

86

console.log(isArray([1, 2, 3])); // => true

87

console.log(isArray({})); // => false

88

console.log(isArray(null)); // => false

89

console.log(isArray(undefined)); // => false

90

console.log(isArray('string')); // => false

91

console.log(isArray(42)); // => false

92

console.log(isArray(function(){})); // => false

93

94

// Edge cases

95

console.log(isArray('[]')); // => false (string, not array)

96

console.log(isArray(document.querySelectorAll('div'))); // => false (NodeList, not array)

97

98

// Arrays with properties

99

var arr = [1, 2, 3];

100

arr.customProperty = 'value';

101

console.log(isArray(arr)); // => true

102

103

// Array-like objects

104

var arrayLike = { 0: 'a', 1: 'b', length: 2 };

105

console.log(isArray(arrayLike)); // => false

106

```

107

108

## Migration Note

109

110

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

111

112

```javascript

113

// Modern approach (when IE8 support not needed)

114

console.log(Array.isArray([])); // => true

115

116

// Polyfill approach (for IE8 and older Node.js versions)

117

var isArray = require('isarray');

118

console.log(isArray([])); // => true

119

```