Skip to content

Latest commit

 

History

History
34 lines (21 loc) · 862 Bytes

no-instanceof-array.md

File metadata and controls

34 lines (21 loc) · 862 Bytes

Prefer Array.isArray static method over instanceof Array

To test whether or not a variable is an array, it's better to use the native method Array.isArray over using the instanceof operator, since it returns false for arrays created in a different global scope, such as an iframe.

This method is available since ES5 and is supported in all major browsers.

Rule Details

This rule is aimed to flag usages of the instanceof operator to test if a value is an array, and suggest using Array.isArray() instead.

The following patterns are considered problems:

if (a instanceof Array) {
  //...
}

var isArray = a instanceof Array;

The following patterns are not considered problems:

if (Array.isArray(a)) {
  //...
}

var isArray = Array.isArray(a);

Version

This rule was introduced in eslint-plugin-wix-editor 1.0.2.