课程: JavaScript: Arrays

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Reformat data with map

Reformat data with map

- [Instructor] Have you ever been presented with an array that isn't quite what you need? It has all the necessary data but that data just needs a little bit of massaging. Let's take this array of grades as an example. You have the grades and they all need to have five points added to them. This is where the array method map comes in. The map array method generates a new array based on the function applied to each element in the array you're iterating over. The syntax for maps should look really familiar. We have seen the same syntax with for each, find, find index, and a few other array methods. So hopefully that will help you grasp how to get started with using map. The only difference you might notice is that we have the array method set to a new variable. This variable can be named whatever you'd like and whatever is relevant for your code. We'll call it new here since we're returning a new array. Before we move on to…

内容