Stop using the traditional “for-loop” and start using forEach(). Although for-loop does have its perks, but forEach() is what’s in and since I’m a person who likes to follow the latest trends, I lean more towards forEach() rather the for loop. So, how does forEach() method work in JavaScript … let’s see some examples:
Let say you have a list of items which you want to loop through individually. Let’s see the traditional for loop method first:
Now let’s have a look at forEach() loop in javascript.
In line 3, individual element of the list gets passed into the variable ‘item’ which is then printed on the console.
You could also loop though 2 different lists and have them interact, so as to have a nested loop like so:
In the above example, the values of the second array “age2” is matched with the values of the 1st array. And if they match, then that value is being printed on the console. Simple right!
Although we could use includes() method for the example above, but we’re focusing on forEach() method in this article, so I won’t go into that.
Alright so that’s the essence of what forEach() in javascript can do. There is 1 more thing that it does. It’s that it tracks the index of the element of the list too. Here let me show you:
And that’s a wrap!
Hopefully I’ve managed to help you understand how exactly forEach() in JavaScript works, and of course, it also works exactly the same for TypeScript as well. Please like and share if this helped you. Have a great one.
Recent Posts
- Experience the thrill of high RTP slots at Online Pokies NZ: top picks for
- Maximizing Casino Offers and Bonuses: Foreign Options, Free Spins, and Security
- Exploring Neosurf Casinos Australia: the ultimate destination for real money pokies and
- Top 10 casino en ligne Belgique : comment choisir une licence fiable
- Casino Bonus Ohne Einzahlung 2026: So starten Sie erfolgreich in Deutschland
Recent Comments
Archives
- September 2026
- August 2026
- July 2026
- June 2026
- May 2026
- October 2025
- August 2025
- October 2024
- September 2024
- August 2024
- June 2024
- January 2024
- November 2023
- October 2023
- September 2023
- August 2023
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- 03_07_PL_AKS
- 08_07_fr_work
- 21
- aks 1 en
- aks 1 pl
- aks 18
- aks 28
- aks 3 en
- aks 31
- Angular
- AWS
- Backend Development
- Betriot
- Big Data
- Blog
- Cloud
- crypto 01
- crypto 05
- crypto 15
- crypto 19 en
- crypto 20
- crypto 20.05
- crypto 21.05
- crypto 29
- crypto 5
- Database
- Deployment
- DevOps
- Docker
- Entertainment
- fi
- Frontend Development
- Game
- GitHub
- Google Cloud Platform
- hu
- Installations
- it
- Java
- JavaScript
- jeux
- KZ 12633
- Linux
- MySQL
- Networking
- News
- Nine Casino
- nl
- no
- NodeJS
- Online casino
- Operating System
- Pin Up Casino
- Post
- public
- Python
- Python Flask
- Report
- Security
- Server
- sport
- SpringBoot
- Subdomain
- sushicasino 13
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
- Παιχνίδια
- Στοιχηματικές
- Блог
Search
Recent Post
Experience the thrill of high RTP slots
- 2 September, 2026
- 5 min read
Maximizing Casino Offers and Bonuses: Foreign Options,
- 2 September, 2026
- 1 min read
Exploring Neosurf Casinos Australia: the ultimate destination
- 2 September, 2026
- 5 min read