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 trialBarbara Wiacek
9,901 PointsHow would this code look like without the new arrow syntax?
How would this code look like without the new arrow syntax?
fruits.forEach(fruit => console.log(fruit));
3 Answers
Ashley Carpenter
13,393 PointsHey, it would like like this:
for (var f in fruit) {
console.log(f);
}
Karan Nahar
16,157 PointsHi Barbara. This is what it would look like without arrow syntax.
fruits.forEach(function(fruit){
console.log(fruit);
});
Barbara Wiacek
9,901 PointsThanks, I think writing it in the "old" way makes it easier to comprehend what the method is actually doing than using the arrow syntax. The information that I was missing is that the forEach() method executes a function which can take the array element as an argument. Doing it with the arrow syntax may look more intuitive but it is not if you don't know these basics.
Ashley Carpenter
13,393 PointsAshley Carpenter
13,393 PointsSee the attached, MSDN is a great JS resource: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in
Barbara Wiacek
9,901 PointsBarbara Wiacek
9,901 PointsThat would be the for...in statement and not the forEach method, which is what I asked about.
Ashley Carpenter
13,393 PointsAshley Carpenter
13,393 PointsIt would have exactly the same result. If you're looking for the exact same prototype function you've used it's
As seen here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach