Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/jenkins/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何检查Typescript对象数组中的多个值?_Javascript_Arrays_Typescript - Fatal编程技术网

Javascript 如何检查Typescript对象数组中的多个值?

Javascript 如何检查Typescript对象数组中的多个值?,javascript,arrays,typescript,Javascript,Arrays,Typescript,在我的Typescript项目中,我在下面的数组中存储了许多对象 我删除了一些数据,使代码更易于阅读: 我试图写一些代码来检查所有的exerciseComplete值是否都是真的 如果所有这些都是真的,我想执行某个动作。如果其中至少有一个为FALSE,则我希望执行不同的操作 我可以使用下面的For循环遍历对象,但我不确定如何检查所有exerciseComplete值 有人能告诉我如何使用此循环检查上述内容吗?创建一个阵列副本,在其中完成练习,然后比较两种大小 let workoutExercis

在我的Typescript项目中,我在下面的数组中存储了许多对象

我删除了一些数据,使代码更易于阅读:

我试图写一些代码来检查所有的exerciseComplete值是否都是真的

如果所有这些都是真的,我想执行某个动作。如果其中至少有一个为FALSE,则我希望执行不同的操作

我可以使用下面的For循环遍历对象,但我不确定如何检查所有exerciseComplete值


有人能告诉我如何使用此循环检查上述内容吗?

创建一个阵列副本,在其中完成练习,然后比较两种大小

let workoutExercisesDone = workoutExercises.filter(exercise => exercise.exerciseComplete); //this will filter yout array by exercises finished
然后比较两个长度是否相等

workoutExercisesDone == workoutExercises //true means that all exercises are done

创建一个完成练习的阵列副本,然后比较两种大小

let workoutExercisesDone = workoutExercises.filter(exercise => exercise.exerciseComplete); //this will filter yout array by exercises finished
然后比较两个长度是否相等

workoutExercisesDone == workoutExercises //true means that all exercises are done
使用

使用


Array.every将帮助您检查数组中的所有元素是否都通过

every方法测试数组中的所有元素是否通过所提供函数实现的测试。它返回一个布尔值

const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true

Array.every将帮助您检查数组中的所有元素是否都通过

every方法测试数组中的所有元素是否通过所提供函数实现的测试。它返回一个布尔值

const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true

看看和。这能回答你的问题吗?看看和。这能回答你的问题吗?
const isBelowThreshold = (currentValue) => currentValue < 40;

const array1 = [1, 30, 39, 29, 10, 13];

console.log(array1.every(isBelowThreshold));
// expected output: true