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 trialMaximilian Skoglund Lartell
6,108 PointsWhy does not .map work when I use curly braces in the call back?
When I use curly braces in the callback function within the .map method no list is shown. When these are removed however, it seems to be working. How come?
This does'nt work,
function generateOptions(data) {
const options = data.map( item => {
<option value='${item}'>'${item}'</option>
})
select.innerHTML = options;
}
This does.
function generateOptions(data) {
const options = data.map( item =>
<option value='${item}'>'${item}'</option>
)
select.innerHTML = options;
}
2 Answers
Blake Larson
13,014 PointsWhen the only statement in an arrow function is return
, we can remove return
and remove
the surrounding curly brackets. If you have the curly braces you need to have a return
.
Zaid Khan
12,769 PointsThank you Blake for this. Should be marked as the best answer.