Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Impara Sfida: Selezionare Dati Specifici Utilizzando filter() | Metodi Avanzati degli Array e Trasformazioni
Strutture Dati JavaScript

bookSfida: Selezionare Dati Specifici Utilizzando filter()

Compito

Dato un array di oggetti studente, utilizzare il metodo filter() per creare un nuovo array chiamato highScorers che includa solo gli studenti con punteggi d'esame maggiori o uguali a 90.

  • L'array originale è fornito come students, contenente oggetti che rappresentano studenti con le proprietà name e score.
  • Verificare se il punteggio dello studente è maggiore o uguale a 90.
  • Utilizzare il metodo filter() sull'array students per creare un nuovo array, highScorers, che includa solo gli studenti con punteggi alti.
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

Output atteso:

Alice
Charlie
Emma

Il metodo filter() crea un nuovo array includendo solo gli elementi che soddisfano la condizione specificata nella funzione di callback.

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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 5. Capitolo 4

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

Suggested prompts:

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

bookSfida: Selezionare Dati Specifici Utilizzando filter()

Scorri per mostrare il menu

Compito

Dato un array di oggetti studente, utilizzare il metodo filter() per creare un nuovo array chiamato highScorers che includa solo gli studenti con punteggi d'esame maggiori o uguali a 90.

  • L'array originale è fornito come students, contenente oggetti che rappresentano studenti con le proprietà name e score.
  • Verificare se il punteggio dello studente è maggiore o uguale a 90.
  • Utilizzare il metodo filter() sull'array students per creare un nuovo array, highScorers, che includa solo gli studenti con punteggi alti.
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

Output atteso:

Alice
Charlie
Emma

Il metodo filter() crea un nuovo array includendo solo gli elementi che soddisfano la condizione specificata nella funzione di callback.

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

Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 5. Capitolo 4
some-alt