Created
February 2, 2021 10:30
-
-
Save Theo-denBlanken/4d06982a0ce718dbef0680c96ee0688d to your computer and use it in GitHub Desktop.
Overeenkomst tussen for-lus en forEach-lus bij introductie forEach()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const steden = ['Emmen', 'Amersfoort', 'Alkmaar', 'IJmuiden', 'Hilversum', 'Zaandam', 'Hoofddorp', 'Hoorn', 'Medemblik', 'Leiden', 'Almere'] | |
document.body.innerHTML = '<h1>Steden</h1>'; | |
// forEach - lus | |
steden.forEach(stad => { | |
document.body.innerHTML += stad; | |
document.body.innerHTML += '<br>'; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const steden = ['Emmen', 'Amersfoort', 'Alkmaar', 'IJmuiden', 'Hilversum', 'Zaandam', 'Hoofddorp', 'Hoorn', 'Medemblik', 'Leiden', 'Almere'] | |
document.body.innerHTML = '<h1>Steden</h1>'; | |
// for-lus | |
for( let i=0; i<steden.length; i++ ) { | |
document.body.innerHTML += steden[i]; | |
document.body.innerHTML += '<br>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Dit is een eerste kennismaking met de forEach();
Kopieer eenvan beide scripts en plak die in de console van je webbrowser.
Na het vernieuwen van de browser kun je dat ook met het andere scriptje doen en je ziet hetzelfde resultaat.