I'm trying to save the names of the students who scored 80 or more in a variable, but I couldn't manage to do it with filter, it returns the whole object although I specified that I want it to print the key values of these objects only, which is the names of these students.
My code:
// Students names/scores
let students = [
{name: "Ahmed" , score: 84},
{name: "Samira" , score: 69},
{name: "Dana" , score: 75},
{name: "Basil" , score: 100},
{name: "Fahad" , score: 91},
{name: "Aljawhara" , score: 80},
{name: "Fadi" , score: 70},
]
// Students who scored 80 or more using filter
let studentsScoredMoreThan80 = students.filter((item,index,array) => {
if(item.score >= 80) return item.name;
})
console.log(studentsScoredMoreThan80);
How do I get just the names of the students who scored 80 or more?