BOOK FOUR - CHAPTER 4 - SHAPING DATA WITH ARRAY METHODS (find forEach map filter reduce)
Copy the code below into the JavaScript file, and follow the instructions in the comments.
const planets = ["mercury", "venus", "earth", "mars", "jupiter", "saturn", "uranus", "neptune"]
-
Use the forEach method to add the name of each planet to a section element in your HTML with an id of "planets". Use string templates to construct the DOM elements.
-
Use the map method to create a new array where the first letter of each planet is capitalized. Use the
toUpperCase()
method on strings. -
Use the filter method to create a new array that contains planets with the letter 'e'. Use the
includes()
method on strings. -
Use the reduce method to create a sentence from the words in the following array const words = ["The", "early", "bird", "might", "get", "the", "worm", "but", "the", "second", "mouse", "gets", "the", "cheese"]
MORE PRACTICE: SPAM Learning Objective:
- Accessing data within an array of objects
- Build a list of email addresses of all the customer's contacts
- From the customers array that contains the emails we need to retrieve extract just the customers' contact email addresses and store them in a new array
MORE PRACTICE: DOTARD AND SIMBLETON
- Use forEach() to see all the customers and their adddress
- Use filter() to see businesses in NY
- Use filter() to see businesses in manufacturing industry
- Use map() to create an array of purchasing agents
- Add the company and telephone number
- Use find() to search for custoers - Create an input field and capture the key press event
- Refactor to search for first name of purchasing agents
- Refactor code to search first and last name for variable
- Use reduce() to calculate order total
Lightning Exercise 1: Use the reduce method on the following array to determine how much total rain fell last month. const monthlyRainfall = [23, 13, 27, 20, 20, 31, 33, 26, 19, 12, 14, 12, 10] const totalRainfall = monthlyRainfall.reduce()
Lightning Exercise 2: Use the reduce method on the following array to build a sentence. const words = ["The", "quick", "brown", "fox", "jumped", "over", "the", "lazy", "dog"] const sentence = words.reduce()
PRACTICE: BIG SPENDERS Use the filter method to get all the big spenders in the main array into a new one