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 trialJuneau Lim
13,362 PointsWhy is mine printing empty array at the and?
const names = ['Selma', 'Ted', 'Mike', 'Sam', 'Sharon', 'Marvin'];
let sNames = [];
names.forEach((name, index) => console.log(`${index+1}) ${name}`));
// 1) Selma
// 2) Ted
// 3) Mike
// 4) Sam
// 5) Sharon
// 6) Marvin
// []
It seems so stange.
2 Answers
KRIS NIKOLAISEN
54,972 PointsI copied your code into a workspace and ran it and it printed just the names as it should.
treehouse:~/workspace$ node app.js
1) Selma
2) Ted
3) Mike
4) Sam
5) Sharon
6) Marvin
Hakan Ergoksen
2,168 PointsI found that what is wrong with your code.
You should remove 'console.log(sNames);' below the forEach loop.
Jesse Vorvick
6,047 PointsThis worked for me.
Juneau Lim
13,362 PointsJuneau Lim
13,362 PointsWell, that's really weird. I feel like I'm hunted by a ghost. Thanks for checking!
Seth Kroger
56,414 PointsSeth Kroger
56,414 PointsIs this in the DevTools console on Chrome?
Juneau Lim
13,362 PointsJuneau Lim
13,362 PointsNo, it was workplace in treehouse. Maybe it was a glitch I guess.