Created
September 22, 2020 19:52
-
-
Save humphd/62778aaaf56422ee0191b7c414f18e54 to your computer and use it in GitHub Desktop.
WEB222 Week 3 - Arrays
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
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