Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Nuradin Sheikh
Nuradin Sheikh
6,211 Points

I'm not sure where I'm going wrong in my for loop in JavaScript?

I am working on bringing back an array that contains names. I want to bring back the array with all the names except Samir. Can someone point me in the right direction where I'm going wrong? I'm sure it's obvious but I can't seem to see where.

const users = [ {name: 'Samir'}, {name: 'Angela'}, {name: 'Beatrice'} ];

for( i = 0; i < users.length; i++){ if(users.name !== 'Samir'){

console.log(users[i]); } }

1 Answer

Jamie Reardon
.a{fill-rule:evenodd;}techdegree seal-36
Jamie Reardon
Treehouse Project Reviewer

You're welcome, just remember these concepts:

  • You were trying to access an object literal with users.name, this wasn't working because users is an array of objects.
  • To access items in an array (in this case, objects), you use bracket notation [0] which accesses the first item in the array as they are zero-indexed.
  • Since loops conveniently use an index to iterate through all the items of an array, you can use that users[i].name