这个 达雷。每 函数是JavaScript中的一个内置函数,用于测试typedArray中的元素是否满足函数提供的条件。 语法:
null
typedarray.every(callback)
参数: 它以回调函数作为参数。 回调函数用于测试typedArray的元素。此回调函数接受下面指定的三个参数-
返回值: 如果函数回调为typedArray中的每个数组元素返回true值,则返回true,否则返回false。
<script> // is_negative function is called to test the // elements of the typedArray element. function is_negative(current_value, index, array) { return current_value < 0; } // Creating a typedArray with some elements const A = new Int8Array([ -5, -10, -15, -20, -25, -30 ]); // Printing whether elements are satisfied by the // functions or not document.write(A.every(is_negative)); </script> |
输出:
true
代码#2:
<script> // is_negative function is called to test the // elements of the typedArray element. function is_positive(current_value, index, array) { return current_value > 0; } // Creating a typedArray with some elements const A = new Int8Array([ -5, -10, -15, -20, -25, -30 ]); // Printing whether elements are satisfied by the // functions or not document.write(A.every(is_positive)); </script> |
输出:
false
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END