TypedArray.every() 函数在 JavaScript 中
TypedArray 的 every() 函数接受一个表示函数名称的字符串值,测试数组中的所有元素是否通过所提供的函数实现的测试。
语法
其语法如下
typedArray.every(function_name)
示例
<html> <head> <title>JavaScript Array every Method</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([64, 89, 65,21, 14, 66, 87, 55 ]); document.write("Contents of the typed array: "+int32View); document.write("<br>"); function testResult(element, index, array) { var ele = element>35 return ele; } result = int32View.every(testResult); if(result) { document.write("all elements are above 35"); }else { document.write("all elements are not above 35"); } </script> </body> </html>
输出
Contents of the typed array: 64,89,65,21,14,66,87,55 all elements are not above 35
示例
<html> <head> <title>JavaScript Array every Method</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([64, 89, 65, 58, 90, 66, 87, 55 ]); document.write("Contents of the typed array: "+int32View); document.write("<br>"); function testResult(element, index, array) { var ele = element>35 return ele; } result = int32View.every(testResult); if(result) { document.write("all elements are above 35"); }else { document.write("all elements are not above 35"); } </script> </body> </html>
输出
Contents of the typed array: 64,89,65,58,90,66,87,55 all elements are above 35
广告