Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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

Piotr Manczak
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Piotr Manczak
Front End Web Development Techdegree Graduate 29,687 Points

arrays

I would like to access the last element of the array: console.log(players[players.length - 1]); isn't correct?

script.js
const players = ['Toni', 'Anwar', 'Mali', 'Carlos', 'Cormac', 'Sariah'];
console.log(players[players.length - 1]);

1 Answer

Laura Coronel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Laura Coronel
Treehouse Teacher

Hi Piotr Manczak

Your code for accessing the last element is correct! 😊 It looks like you may have accidentally deleted your answer to the first task, which is why it's being marked as incorrect.

Add console.log(players[0]); back on the second line, and keep your current code for accessing the last element on the third line. That should do the trick!