Array.prototype.includes()

(標準組み込みオブジェクト > Array > メソッド)
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes

Array.includes(searchElement)
Array.includes(searchElement, fromIndex)

includesメソッドとは、特定の要素が配列や文字列に含まれているかどうか確認するためのメソッドである。主に、配列内や文字列内の要素の存在確認のために使用される。
includesメソッドの戻り値はtrueかfalseのみである。引数に指定した要素が配列内に含まれていればtrueを返し、含まれていない場合はfalseを返す。
また、第2引数に指定した要素の検索を始める位置(インデックス値)を指定することもできる。

var myarray = [1,2,3,4,5];
var res1 = myarray.includes(3);
var res2 = myarray.includes(7);
var res3 = myarray.includes(3,1);
var res4 = myarray.includes(1,2);

console.log(res1) // true
console.log(res2) // false
console.log(res3) // true
console.log(res4) // false
inserted by FC2 system