How to print all students name having percentage more than 70% in JavaScript?

You can filter and display students with percentage more than 70% using various JavaScript approaches. This is useful for grade-based filtering and reporting.

Following are the records of each student:

const studentDetails = [
    {
        studentName: "John",
        percentage: 78
    },
    {
        studentName: "Sam",
        percentage: 68
    },
    {
        studentName: "Mike",
        percentage: 88
    },
    {
        studentName: "Bob",
        percentage: 70
    }
];

Using for Loop

The traditional approach uses a for loop with an if condition to check each student's percentage:

const studentDetails = [
    { studentName: "John", percentage: 78 },
    { studentName: "Sam", percentage: 68 },
    { studentName: "Mike", percentage: 88 },
    { studentName: "Bob", percentage: 70 }
];

console.log("Students with more than 70% marks:");
for (let index = 0; index < studentDetails.length; index++) {
    if (studentDetails[index].percentage > 70) {
        console.log(studentDetails[index].studentName);
    }
}
Students with more than 70% marks:
John
Mike

Using filter() Method

A more modern approach uses the array filter() method:

const studentDetails = [
    { studentName: "John", percentage: 78 },
    { studentName: "Sam", percentage: 68 },
    { studentName: "Mike", percentage: 88 },
    { studentName: "Bob", percentage: 70 }
];

const topStudents = studentDetails
    .filter(student => student.percentage > 70)
    .map(student => student.studentName);

console.log("Top performing students:", topStudents);
Top performing students: [ 'John', 'Mike' ]

Using forEach() Method

You can also use forEach() for a clean iteration approach:

const studentDetails = [
    { studentName: "John", percentage: 78 },
    { studentName: "Sam", percentage: 68 },
    { studentName: "Mike", percentage: 88 },
    { studentName: "Bob", percentage: 70 }
];

console.log("Students above 70%:");
studentDetails.forEach(student => {
    if (student.percentage > 70) {
        console.log(`${student.studentName}: ${student.percentage}%`);
    }
});
Students above 70%:
John: 78%
Mike: 88%

Comparison

Method Readability Returns Array Best For
for loop Good No Simple iteration
filter() + map() Excellent Yes Functional programming
forEach() Good No Side effects only

Conclusion

Use filter() and map() for functional programming style, or traditional for loops for simple iterations. Both approaches effectively filter students based on percentage criteria.

Updated on: 2026-03-15T23:18:59+05:30

625 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements