Challenge: Select Specific Data Using filter()
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 propertiesname
andscore
. - Check if the student's score is greater or equal to 90.
- Use the
filter()
method on thestudents
array to create a new array,highScorers
, that includes only the students with high scores.
123456789101112131415const 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); }
Expected output:
Alice
Charlie
Emma
The filter()
method will create a new array by including only the elements that satisfy the condition specified in the callback function.
123456789101112131415const 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); }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Запитайте мені питання про цей предмет
Сумаризуйте цей розділ
Покажіть реальні приклади
Awesome!
Completion rate improved to 2.27
Challenge: Select Specific Data Using filter()
Свайпніть щоб показати меню
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 propertiesname
andscore
. - Check if the student's score is greater or equal to 90.
- Use the
filter()
method on thestudents
array to create a new array,highScorers
, that includes only the students with high scores.
123456789101112131415const 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); }
Expected output:
Alice
Charlie
Emma
The filter()
method will create a new array by including only the elements that satisfy the condition specified in the callback function.
123456789101112131415const 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); }
Дякуємо за ваш відгук!