I have an array object containing the grades of students.
I want to map over the item and return the indexes that match when a student has a grade over 40%;
I have scaled down the array in this sample.
students = [{
name: "Amber",
age: 18,
grade: 58
}, {
name: "Andrew",
age: 19,
grade: 72
}, {
name: "Lisa",
age: 22,
grade: 80
}, {
name: "James",
age: 19,
grade: 41
}];
const topStudents = students.map((student) => {
if (student.grade > 60) {
// Return the indexs of the students array if their grade is above 60,
// In this case Andrew, Lisa - thus retun the result of the indexes - [1,2];
return student;
}
});
console.log(topStudents);