这个 达雷。一些 是JavaScript中的一个内置函数,用于检查typedArray的某些元素是否满足给定函数实现的测试。 语法:
null
typedarray.some(callback)
参数: 它使用参数回调函数,这个回调函数使用下面指定的三个参数-
返回值: 如果回调函数真正传递所有元素,则返回true,否则返回false。 显示此函数工作的JavaScript代码:
<script> // Creating isNegative() function function isNegative(element, index, array) { return element < 0; } // Creating some typedArrays containing different // positive and negative values const A = new Int8Array([-5, 10, -15, 20, -25 ]); const B = new Int8Array([5, 10, 15, 20, 25 ]); const C = new Int8Array([-10, -20, -30, -40, -50 ]); const D = new Int8Array([0, 0, 0, 0 ]); // Printing true or false on checking document.write(A.some(isNegative) + "<br>" ); document.write(B.some(isNegative) + "<br>" ); document.write(C.some(isNegative) + "<br>" ); document.write(D.some(isNegative)); </script> |
输出:
true false true false
这里的输出是真的,因为typedArray A和C有负元素,B和D typedArray有正元素,这就是为什么它会给出false作为输出。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END