Lesson 9. New array methods
After reading lesson 9, you will
- Know how to construct arrays with Array.from
- Know how to construct arrays with Array.of
- Know how to construct arrays with Array.prototype.fill
- Know how to search in Arrays with Array.prototype.includes
- Know how to search in Arrays with Array.prototype.find
Arrays are probably the most common data structure used in JavaScript. We use them to hold all kinds of data, but sometimes getting the data we want into or out of the array isn’t as easy as it should be. But those tasks just got a lot easier with some of the new array methods that we’ll cover in this lesson.
Consider this
Consider this snippet of jQuery code that grabs all the DOM nodes with a specific CSS class and sets them to the color red. If you were going to implement this from scratch, what considerations would you have to make? For example, if you were to use document.querySelectorAll, which returns a NodeList (not an Array), how would you iterate each node to update its color?