From 811a0cdaf23d3c3bbd0ca5ff5df4ea85a9cec828 Mon Sep 17 00:00:00 2001 From: Masahiro FUJIMOTO Date: Wed, 22 Sep 2021 00:12:32 +0900 Subject: Global_Objects/Array/includes の変換準備 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global_objects/array/includes/index.html | 135 --------------------- .../global_objects/array/includes/index.md | 135 +++++++++++++++++++++ 2 files changed, 135 insertions(+), 135 deletions(-) delete mode 100644 files/ja/web/javascript/reference/global_objects/array/includes/index.html create mode 100644 files/ja/web/javascript/reference/global_objects/array/includes/index.md (limited to 'files') diff --git a/files/ja/web/javascript/reference/global_objects/array/includes/index.html b/files/ja/web/javascript/reference/global_objects/array/includes/index.html deleted file mode 100644 index b78bb5d20e..0000000000 --- a/files/ja/web/javascript/reference/global_objects/array/includes/index.html +++ /dev/null @@ -1,135 +0,0 @@ ---- -title: Array.prototype.includes() -slug: Web/JavaScript/Reference/Global_Objects/Array/includes -tags: - - Array - - JavaScript - - Method - - Prototype - - Reference - - inArray - - in_array - - polyfill - - メソッド -translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes ---- -
{{JSRef}}
- -

includes() メソッドは、特定の要素が配列に含まれているかどうかを true または false で返します。

- -
{{EmbedInteractiveExample("pages/js/array-includes.html")}}
- - - -

構文

- -
arr.includes(valueToFind[, fromIndex])
-
- -

引数

- -
-
valueToFind
-
-

検索する値です。

- -
-

メモ: 文字列や文字を比較するとき、includes()大文字と小文字を区別します

-
-
-
fromIndex {{optional_inline}}
-
この配列内で valueToFind を探し始める位置です。
-
検索される最初の文字は、fromIndex が正の値の場合は、fromIndex で見つかり、fromIndex が負の数の場合は (fromIndex の{{interwiki("wikipedia", "絶対値")}}だけ配列の末尾から文字数を戻った位置が検索開始地点となり)、fromIndex または arr.length + fromIndex で見つかります。
-
既定値は 0 です。
-
- -

返値

- -

{{jsxref("Boolean")}} で、truevalueToFind の値が配列内 (または、fromIndex が指定された場合はそれで示された配列の部分) から見つかった場合です。

- -

ゼロの値はすべて、符号にかかわらず等しいとみなされます (つまり、-00+0 の両方に等しいとみなされます) が、false0 と同じとはみなされません

- -
-

注: 技術的に言えば、includes()sameValueZero アルゴリズムを使用して、指定された要素が見つかったかどうかを確認しています。

-
- -

- -
[1, 2, 3].includes(2)      // true
-[1, 2, 3].includes(4)      // false
-[1, 2, 3].includes(3, 3)   // false
-[1, 2, 3].includes(3, -1)  // true
-[1, 2, NaN].includes(NaN)  // true
-
- -

fromIndex が配列の長さと同じか大きい場合

- -

fromIndex が配列の長さと同じか大きい場合は配列を検索せずに false を返します。

- -
let arr = ['a', 'b', 'c']
-
-arr.includes('c', 3)    // false
-arr.includes('c', 100)  // false
-
- -

計算値のインデックスが 0 より小さい場合

- -

fromIndex が負の値である場合、計算値のインデックスは配列内で valueToFind の円策を開始する位置として使用するよう計算されます。計算値のインデックスが -1 * arr.length 以下の場合は、配列全体が検索されます。

- -
// 配列の長さは 3
-// fromIndex は -100
-// 補正されたインデックスは 3 + (-100) = -97
-
-let arr = ['a', 'b', 'c']
-
-arr.includes('a', -100) // true
-arr.includes('b', -100) // true
-arr.includes('c', -100) // true
-arr.includes('a', -2)   // false
-
- -

ジェネリックメソッドとして使用される includes()

- -

includes() メソッドは意図的にジェネリックになっています。this が Array オブジェクトであることは必須ではないので、他の種類のオブジェクト (例えば配列風オブジェクト) にも適用することができます。

- -

以下の例は、includes() メソッドが関数の arguments オブジェクトに対して使用される様子を示しています。

- -
(function() {
-  console.log(Array.prototype.includes.call(arguments, 'a'))  // true
-  console.log(Array.prototype.includes.call(arguments, 'd'))  // false
-})('a','b','c') 
- - - -

仕様

- - - - - - - - - - - - -
仕様書
{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}
- -

ブラウザーの互換性

- -
-

{{Compat("javascript.builtins.Array.includes")}}

-
- -

関連情報

- - diff --git a/files/ja/web/javascript/reference/global_objects/array/includes/index.md b/files/ja/web/javascript/reference/global_objects/array/includes/index.md new file mode 100644 index 0000000000..b78bb5d20e --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/array/includes/index.md @@ -0,0 +1,135 @@ +--- +title: Array.prototype.includes() +slug: Web/JavaScript/Reference/Global_Objects/Array/includes +tags: + - Array + - JavaScript + - Method + - Prototype + - Reference + - inArray + - in_array + - polyfill + - メソッド +translation_of: Web/JavaScript/Reference/Global_Objects/Array/includes +--- +
{{JSRef}}
+ +

includes() メソッドは、特定の要素が配列に含まれているかどうかを true または false で返します。

+ +
{{EmbedInteractiveExample("pages/js/array-includes.html")}}
+ + + +

構文

+ +
arr.includes(valueToFind[, fromIndex])
+
+ +

引数

+ +
+
valueToFind
+
+

検索する値です。

+ +
+

メモ: 文字列や文字を比較するとき、includes()大文字と小文字を区別します

+
+
+
fromIndex {{optional_inline}}
+
この配列内で valueToFind を探し始める位置です。
+
検索される最初の文字は、fromIndex が正の値の場合は、fromIndex で見つかり、fromIndex が負の数の場合は (fromIndex の{{interwiki("wikipedia", "絶対値")}}だけ配列の末尾から文字数を戻った位置が検索開始地点となり)、fromIndex または arr.length + fromIndex で見つかります。
+
既定値は 0 です。
+
+ +

返値

+ +

{{jsxref("Boolean")}} で、truevalueToFind の値が配列内 (または、fromIndex が指定された場合はそれで示された配列の部分) から見つかった場合です。

+ +

ゼロの値はすべて、符号にかかわらず等しいとみなされます (つまり、-00+0 の両方に等しいとみなされます) が、false0 と同じとはみなされません

+ +
+

注: 技術的に言えば、includes()sameValueZero アルゴリズムを使用して、指定された要素が見つかったかどうかを確認しています。

+
+ +

+ +
[1, 2, 3].includes(2)      // true
+[1, 2, 3].includes(4)      // false
+[1, 2, 3].includes(3, 3)   // false
+[1, 2, 3].includes(3, -1)  // true
+[1, 2, NaN].includes(NaN)  // true
+
+ +

fromIndex が配列の長さと同じか大きい場合

+ +

fromIndex が配列の長さと同じか大きい場合は配列を検索せずに false を返します。

+ +
let arr = ['a', 'b', 'c']
+
+arr.includes('c', 3)    // false
+arr.includes('c', 100)  // false
+
+ +

計算値のインデックスが 0 より小さい場合

+ +

fromIndex が負の値である場合、計算値のインデックスは配列内で valueToFind の円策を開始する位置として使用するよう計算されます。計算値のインデックスが -1 * arr.length 以下の場合は、配列全体が検索されます。

+ +
// 配列の長さは 3
+// fromIndex は -100
+// 補正されたインデックスは 3 + (-100) = -97
+
+let arr = ['a', 'b', 'c']
+
+arr.includes('a', -100) // true
+arr.includes('b', -100) // true
+arr.includes('c', -100) // true
+arr.includes('a', -2)   // false
+
+ +

ジェネリックメソッドとして使用される includes()

+ +

includes() メソッドは意図的にジェネリックになっています。this が Array オブジェクトであることは必須ではないので、他の種類のオブジェクト (例えば配列風オブジェクト) にも適用することができます。

+ +

以下の例は、includes() メソッドが関数の arguments オブジェクトに対して使用される様子を示しています。

+ +
(function() {
+  console.log(Array.prototype.includes.call(arguments, 'a'))  // true
+  console.log(Array.prototype.includes.call(arguments, 'd'))  // false
+})('a','b','c') 
+ + + +

仕様

+ + + + + + + + + + + + +
仕様書
{{SpecName('ESDraft', '#sec-array.prototype.includes', 'Array.prototype.includes')}}
+ +

ブラウザーの互換性

+ +
+

{{Compat("javascript.builtins.Array.includes")}}

+
+ +

関連情報

+ + -- cgit v1.2.3-54-g00ecf