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
相关用法
- JavaScript TypedArray.entries()用法及代码示例
- JavaScript TypedArray.sort()用法及代码示例
- JavaScript TypedArray.indexOf()用法及代码示例
- JavaScript TypedArray.fill()用法及代码示例
- JavaScript TypedArray.forEach()用法及代码示例
- JavaScript TypedArray.join()用法及代码示例
- JavaScript TypedArray.values()用法及代码示例
- JavaScript TypedArray.toString()用法及代码示例
- JavaScript TypedArray.of()用法及代码示例
- JavaScript TypedArray.map()用法及代码示例
- JavaScript TypedArray.subarray()用法及代码示例
- JavaScript TypedArray.set()用法及代码示例
- JavaScript TypedArray.copyWithin()用法及代码示例
- JavaScript TypedArray.keys()用法及代码示例
- JavaScript TypedArray.lastIndexOf()用法及代码示例
- JavaScript TypedArray.reverse()用法及代码示例
- JavaScript TypedArray.find()用法及代码示例
- JavaScript TypedArray.findIndex()用法及代码示例
- JavaScript TypedArray.filter()用法及代码示例
- JavaScript TypedArray.includes()用法及代码示例
注:本文由纯净天空筛选整理自Karthikeya Boyini大神的英文原创作品 TypedArray.every() function in JavaScript。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。