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 Array Iteration Methods Array Iteration Examples Using forEach()

Tamella Hajiyeva
seal-mask
.a{fill-rule:evenodd;}techdegree
Tamella Hajiyeva
Full Stack JavaScript Techdegree Student 6,678 Points

Different solution, is this acceptable?

Just curious if this would be acceptable way to write the solution for this assignment

//filter names with letter S const names = ['Selma', 'Ted', 'Mike', 'Sam', 'Sharon', 'Marvin']; let sNames = [] names.forEach(name =>{ if(name[0][0] === 'S'){ sNames.push(name)

}}) console.log(sNames)

1 Answer

Your code works fine.

Instead of if(name[0][0] === 'S'), it would be slightly clearer to use if(name[0] === 'S'). If you want to check if the second letter is an 'a', either if(name[1][0] === 'a') or if(name[1] === 'a') would work.