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.

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.