JavaScript JavaScript Arrays Store Multiple Values in an Array Access Array Elements by Index

Juan Pablo Castrillon
Juan Pablo Castrillon
863 Points

I am using console.log(players [0] )

script.js
const players = ['Toni', 'Anwar', 'Mali', 'Carlos', 'Cormac', 'Sariah'];

console.log( players[0] );
console.log( players[1] );
console.log( players[2] );
console.log( players[3] );
console.log( players[4] );
console.log( players[5] );

1 Answer

Peter Vann
MOD
Peter Vann
Treehouse Moderator 35,207 Points

Hi Juan!

This passes both:

const players = ['Toni', 'Anwar', 'Mali', 'Carlos', 'Cormac', 'Sariah'];

console.log( players[0] ); /*** Task 1 ***/

console.log( players[players.length - 1]; /*** Task 2 ***/

/*** console.log( players[5] ); Would also work (passes Task 2)... ***/

I hope that helps.

Stay safe and happy coding!