Haaste: Valitse Tiettyjä Tietoja Filter()-Metodilla
Tehtävä
Saat taulukon opiskelijaolioita. Käytä filter()-metodia luodaksesi uuden taulukon nimeltä highScorers, joka sisältää vain ne opiskelijat, joiden koepisteet ovat suuremmat tai yhtä suuret kuin 90.
- Alkuperäinen taulukko on nimeltään
students, ja se sisältää olioita, joissa on ominaisuudetnamejascore. - Tarkista, onko opiskelijan pisteet suuremmat tai yhtä suuret kuin 90.
- Käytä
filter()-metodiastudents-taulukossa luodaksesi uuden taulukonhighScorers, joka sisältää vain korkeat pisteet saaneet opiskelijat.
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); }
Odotettu tuloste:
Alice
Charlie
Emma
filter()-metodi luo uuden taulukon sisältäen vain ne alkiot, jotka täyttävät palautetun ehdon callback-funktiossa.
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); }
Kiitos palautteestasi!
Kysy tekoälyä
Kysy tekoälyä
Kysy mitä tahansa tai kokeile jotakin ehdotetuista kysymyksistä aloittaaksesi keskustelumme
Can you explain how the filter() method works in this example?
What would happen if I changed the score threshold to 85?
Can you show how to display both the name and score of the high scorers?
Awesome!
Completion rate improved to 2.27
Haaste: Valitse Tiettyjä Tietoja Filter()-Metodilla
Pyyhkäise näyttääksesi valikon
Tehtävä
Saat taulukon opiskelijaolioita. Käytä filter()-metodia luodaksesi uuden taulukon nimeltä highScorers, joka sisältää vain ne opiskelijat, joiden koepisteet ovat suuremmat tai yhtä suuret kuin 90.
- Alkuperäinen taulukko on nimeltään
students, ja se sisältää olioita, joissa on ominaisuudetnamejascore. - Tarkista, onko opiskelijan pisteet suuremmat tai yhtä suuret kuin 90.
- Käytä
filter()-metodiastudents-taulukossa luodaksesi uuden taulukonhighScorers, joka sisältää vain korkeat pisteet saaneet opiskelijat.
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); }
Odotettu tuloste:
Alice
Charlie
Emma
filter()-metodi luo uuden taulukon sisältäen vain ne alkiot, jotka täyttävät palautetun ehdon callback-funktiossa.
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); }
Kiitos palautteestasi!