JavaScript 中的 TypedArray.every() 函数
htmljavascriptprogramming scripts更新于 2024/10/17 20:28:17
TypedArray 的 every() 函数接受一个表示函数名称的字符串值,测试数组中的所有元素是否通过了所提供函数实现的测试。
语法
其语法如下
typedArray.every(function_name)
示例
<html>
<head>
<title>JavaScript 数组 every 方法</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([64, 89, 65,21, 14, 66, 87, 55 ]);
document.write("类型化数组的内容:"+int32View);
document.write("<br>");
function testResult(element, index, array) {
var ele = element>35
return ele;
}
result = int32View.every(testResult);
if(result) {
document.write("所有元素均超过 35");
}else {
document.write("所有元素均不超过 35");
}
</script>
</body>
</html>
输出
类型化数组的内容:64,89,65,21,14,66,87,55 所有元素均不大于 35
示例
<html>
<head>
<title>JavaScript 数组每个方法</title>
</head>
<body>
<script type="text/javascript">
var int32View = new Int32Array([64, 89, 65, 58, 90, 66, 87, 55 ]);
document.write("类型化数组的内容:"+int32View);
document.write("<br>");
function testResult(element, index, array) {
var ele = element>35
return ele;
}
result = int32View.every(testResult);
if(result) {
document.write("所有元素均高于 35");
}else {
document.write("所有元素均不高于 35");
}
</script>
</body>
</html>
输出
类型化数组的内容:64,89,65,58,90,66,87,55 所有元素均大于 35
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

