當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


JavaScript TypedArray.includes()用法及代碼示例


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

相關用法


注:本文由純淨天空篩選整理自Karthikeya Boyini大神的英文原創作品 TypedArray.includes() function in JavaScript。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。