Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Filtering Students by Exam Scores | Advanced Array Operations
JavaScript Data Structures
course content

Contenido del Curso

JavaScript Data Structures

JavaScript Data Structures

1. Introduction and Prerequisites
2. Objects Fundamentals
3. Advanced Object Manipulation
4. Mastering Arrays
5. Advanced Array Operations

bookChallenge: Filtering Students by Exam Scores

Task

Given an array of student objects, use the filter() method to create a new array called highScorers that includes only the students with exam scores greater than or equal to 90.

  • The original array is given as students, containing objects representing students with properties name and score.
  • Check if the student's score is greater or equal to 90.
  • Use the filter() method on the students array to create a new array, highScorers, that includes only the students with high scores.
123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.___((___) => { return ___; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

Expected output:

The filter() method will create a new array by including only the elements that satisfy the condition specified in the callback function.

123456789101112131415
const students = [ { name: "Alice", score: 92 }, { name: "Bob", score: 87 }, { name: "Charlie", score: 95 }, { name: "David", score: 78 }, { name: "Emma", score: 90 }, ]; const highScorers = students.filter((student) => { return student.score >= 90; }); for (let i = 0; i < highScorers.length; i += 1) { console.log(highScorers[i].name); }
copy

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 5. Capítulo 4
some-alt