Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Array.isArray()

翻譯不完整。請協助 翻譯此英文文件

Array.isArray() 檢查傳入的值是否為陣列 (Array)

語法

Array.isArray(obj)

Parameters (參數)

obj
要檢查的物件。

Description (描述)

檢查傳入的物件是否為陣列 (Array),是陣列回傳 true,不是則回傳 false.

更多細節請參照 “Determining with absolute accuracy whether or not a JavaScript object is an array”.

Examples (範例)

// 下方都回傳 true
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
// 小細節: Array.prototype 本身是陣列:
Array.isArray(Array.prototype); 

// 下方都回傳 false
Array.isArray();
Array.isArray({});
Array.isArray(null);
Array.isArray(undefined);
Array.isArray(17);
Array.isArray('Array');
Array.isArray(true);
Array.isArray(false);
Array.isArray({ __proto__: Array.prototype });

Polyfill (補填)

如果 Array.isArray() 不存在於您的環境,在其他程式碼前執行下列程式碼可建置 Array.isArray()

if (!Array.isArray) {
  Array.isArray = function(arg) {
    return Object.prototype.toString.call(arg) === '[object Array]';
  };
}

Specifications (規範)

Specification Status Comment
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.isArray' in that specification.
Standard Initial definition. Implemented in JavaScript 1.8.5.
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Array.isArray' in that specification.
Standard  

Browser compatibility (瀏覽器相容性)

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 5 4.0 (2.0) 9 10.5 5
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) 4.0 (2.0) (Yes) (Yes) (Yes)

Based on Kangax's compat table.

See also (相關資料)

文件標籤與貢獻者

 此頁面的貢獻者: m80126colin, JamesWen, onlinemad
 最近更新: m80126colin,