您可以使用for循环,并使用if条件检查百分比是否大于70。
以下是每个学生的记录-
const studentDetails= [ { studentName:"John", percentage:78 }, { studentName:"Sam", percentage:68 }, { studentName:"Mike", percentage:88 }, { studentName:"Bob", percentage:70 } ]
现在,对百分比大于70的学生使用for循环和et条件-
for(var index=0;index<studentDetails.length;index++) { if(studentDetails[index].percentage > 70) { // } }
const studentDetails= [ { studentName:"John", percentage:78 }, { studentName:"Sam", percentage:68 }, { studentName:"Mike", percentage:88 }, { studentName:"Bob", percentage:70 } ] for(var index=0;index<studentDetails.length;index++){ if(studentDetails[index].percentage > 70){ console.log("Student Name which has more than 70 %="+studentDetails[index].studentName); } }
要运行以上程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo68.js。这将产生以下输出-
PS C:\Users\Amit\JavaScript-code> node demo68.js Student Name which has more than 70 %=John Student Name which has more than 70 %=Mike