Before proceeding, be sure you’ve completed Studio: JavaScript 2).
Note: The video focuses on concepts from the Studio, but you are expected to be comfortable with the contents of all the prep material, which included more in-depth and broad coverage of JavaScript’s Objects.
var a = ["Hi", "Bye", "this", "that", "pop"]
// Print each item in the array
a.forEach(function(a) { console.log(a); } )
// Find the total number of letters of all words
a.reduce(function(accumulator, item) { return accumulator+item.length; }, 0)
// Make a new array with each word doubled (I.e., Hi becomes HiHi)
a.map(function(item) { return item+item; })
// Remove words that start with t
a.filter(function(item) { return item[0]!='t'; })
In general:
forEach
can be used to apply an operation to each element of the array.reduce
can be used to find a single “result” from the arraymap
can be used to create a new array based on the existing arrayfilter
can be used to remove unwanted elements that match a pattern