当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。