TypedArray 對象的 includes() 函數接受一個值並驗證此類型化數組是否包含指定的元素。如果數組包含給定元素,則返回 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
相關用法
- JavaScript TypedArray.indexOf()用法及代碼示例
- JavaScript TypedArray.sort()用法及代碼示例
- JavaScript TypedArray.fill()用法及代碼示例
- JavaScript TypedArray.every()用法及代碼示例
- JavaScript TypedArray.forEach()用法及代碼示例
- JavaScript TypedArray.join()用法及代碼示例
- JavaScript TypedArray.values()用法及代碼示例
- JavaScript TypedArray.toString()用法及代碼示例
- JavaScript TypedArray.of()用法及代碼示例
- JavaScript TypedArray.map()用法及代碼示例
- JavaScript TypedArray.subarray()用法及代碼示例
- JavaScript TypedArray.set()用法及代碼示例
- JavaScript TypedArray.copyWithin()用法及代碼示例
- JavaScript TypedArray.keys()用法及代碼示例
- JavaScript TypedArray.lastIndexOf()用法及代碼示例
- JavaScript TypedArray.reverse()用法及代碼示例
- JavaScript TypedArray.find()用法及代碼示例
- JavaScript TypedArray.findIndex()用法及代碼示例
- JavaScript TypedArray.filter()用法及代碼示例
- JavaScript TypedArray.entries()用法及代碼示例
注:本文由純淨天空篩選整理自Karthikeya Boyini大神的英文原創作品 TypedArray.includes() function in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。