DébutantNon commencé
Exercice 5.2 · 5 min · 0 tentative
Accéder aux éléments d'un tableau
🎯 Objectif
Utiliser les index pour accéder aux éléments d'un tableau.
📖 Contexte
Chaque élément d'un tableau a un index (sa position). Attention : l'index commence à 0 !
const animaux = ["chat", "chien", "oiseau"]
// index: 0 1 2
Accès par index
animaux[0] // "chat" (premier)
animaux[1] // "chien" (deuxième)
animaux[2] // "oiseau" (troisième)
Propriété length
animaux.length // 3 (nombre d'éléments)
animaux[animaux.length - 1] // "oiseau" (dernier)
📝 Consigne
Le tableau pays contient 5 pays. Complète le code pour :
- Afficher le premier pays (Suisse)
- Afficher le troisième pays (Allemagne)
- Afficher le dernier pays avec
.length - Afficher le nombre total de pays
Résultat attendu :
Suisse
Allemagne
Autriche
5
Objectifs
- Accéder au premier élément
- Accéder au troisième élément
- Utiliser length pour le dernier
- Afficher la longueur
- Affiche Suisse
Lis bien les instructions et lance-toi !
Indices (0/3)
Indice 1 verrouillé
Indice 2 verrouillé
Indice 3 verrouillé