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
6,211 PointsI'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
Treehouse Project ReviewerYou need to add your index variable to the if condition as well:
if(users[i].name !== 'Samir')
Nuradin Sheikh
6,211 PointsNuradin Sheikh
6,211 PointsThank you!!
Jamie Reardon
Treehouse Project ReviewerJamie Reardon
Treehouse Project ReviewerYou're welcome, just remember these concepts:
users.name
, this wasn't working because users is an array of objects.[0]
which accesses the first item in the array as they are zero-indexed.users[i].name