Skip to content

Instantly share code, notes, and snippets.

@humphd
Created September 22, 2020 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save humphd/62778aaaf56422ee0191b7c414f18e54 to your computer and use it in GitHub Desktop.
Save humphd/62778aaaf56422ee0191b7c414f18e54 to your computer and use it in GitHub Desktop.
WEB222 Week 3 - Arrays
let words = ['one', 'two', 'three', 'four', 'five'];
// version 1 - for loop
for(let i = 0; i < words.length; i++) {
let word = words[i];
console.log(word);
}
// version 2 - for-of loop
for(let word of words) {
console.log(word);
}
// version 3 - forEach()
words.forEach(function(word) {
console.log(word);
});
// Create a new array by "mapping" (transforming) the original array
let uppercaseWords = words.map(function(word) {
return word.toUpperCase();
});
console.log(uppercaseWords);
// Create a new array that filters out items not meeting a boolean test
let fourOrMore = words.filter(function(word) {
return word.length > 3;
})
console.log(fourOrMore);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment