includes()TypedArray对象的函数接受一个值,并验证此类型的数组是否包含指定的元素。如果数组包含给定元素,则返回true,否则返回false。
其语法如下
typedArray.includes()
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.includes(66);
if(contains) {
document.write("Array contains the specified element");
}else {
document.write("Array doesn’t contains the specified element");
}
</script>
</body>
</html>输出结果
Contents of the typed array: 21,19,65,21,14,66,87,55 Array contains the specified element
<html>
<head>
<title>JavaScript Array every Method</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([21, 19, 65, 21, 14, 66, 87, 55 ]);
document.write("Contents of the typed array: "+int32View);
document.write("<br>");
var contains = int32View.includes(762);
if(contains) {
document.write("Array contains the specified element");
}else {
document.write("Array doesn’t contains the specified element");
}
</script>
</body>
</html>输出结果
Contents of the typed array: 21,19,65,21,14,66,87,55 Array doesn’t contains the specified element