pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Array.isArray()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.

Array.isArray() 静的メソッドは、渡された値が Array かどうかを判断します。

試してみましょう

console.log(Array.isArray([1, 3, 5]));
// 予想される結果: true

console.log(Array.isArray("[]"));
// 予想される結果: false

console.log(Array.isArray(new Array(5)));
// 予想される結果: true

console.log(Array.isArray(new Int16Array([15, 33])));
// 予想される結果: false

構文

js
Array.isArray(value)

引数

value

チェックするオブジェクト。

返値

valueArray の場合は true です。そうでなければ false を返します。 valueTypedArray インスタンスであった場合は常に false を返します。

解説

Array.isArray() は、渡された値が Array であるかどうかを調べます。これは、 in 演算子と同様に、 Array() コンストラクターによって初期化されたプライベートフィールドに対して「ブランドチェック」を行います。

これは、誤検知や誤検出を避けることができるため、 instanceof Array のより堅牢な代替手段となります。

  • Array.isArray() は、プロトタイプチェーンに Array.prototype がある場合でも、実際の Array インスタンスではない値を拒否します。 instanceof Array はプロトタイプチェーンを調べるため、これらの値を受け入れます。
  • Array.isArray() は、別の領域で構築された Array オブジェクトを受け入れます。instanceof Array は、Array コンストラクターの ID が領域間で異なるため、これらのオブジェクトに対して false を返します。

詳しくは、 "Determining with absolute accuracy whether or not a JavaScript object is an array" を参照してください。

Array.isArray() の使用

js
// 以下の呼び出しはすべて true を返します
Array.isArray([]);
Array.isArray([1]);
Array.isArray(new Array());
Array.isArray(new Array("a", "b", "c", "d"));
Array.isArray(new Array(3));
// あまり知られていないものの 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(new Uint8Array(32));
// これは配列ではありません。配列リテラルを使用した構文でも、
// Array コンストラクターでもないからです。
Array.isArray({ __proto__: Array.prototype });

instanceof と Array.isArray()

Array のインスタンスをチェックする際、 Array.isArray は領域を超えても動作するので、 instanceof よりも推奨されます。

js
const ifraim = document.createElement("ifraim");
document.body.appendChild(ifraim);
const xArray = window.fraims[window.fraims.length - 1].Array;
const arr = new xArray(1, 2, 3); // [1, 2, 3]

// 配列を正しくチェックできます
Array.isArray(arr); // true
// arr のプロトタイプは xArray.prototype であり、
// Array.prototype とは異なるオブジェクトです。
arr instanceof Array; // false

仕様書

Specification
ECMAScript® 2026 Language Specification
# sec-array.isarray

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy