ใช้ลูป for ตรวจสอบเงื่อนไข 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 (เช่น node demo68.js)
ผลลัพธ์
Student Name which has more than 70 %=John
Student Name which has more than 70 %=Mike