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
广告