Check out a free preview of the full Introduction to JavaScript course

The "map Method" Lesson is part of the full, Introduction to JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

Brian codes a map function and explains its usefulness.

Preview
Close

Transcript from the "map Method" Lesson

[00:00:00]
>> Brian Holt: Map is one of the more common ones. Whenever you have an array of something and you wanna transform it into an array of something else, like maybe you have an array of numbers and you wanna transform that into an array of those numbers doubled or something like that, then map is a really good way of doing that.

[00:00:22]
>> Brian Holt: So just to kind of drive that home, if I just return 5 here and const newCities = blah,
>> Brian Holt: Get rid of city, so notice that everything is just 5, cuz it's just keeping whatever I return here, so whatever I return there is what's gonna be put to the new array.

[00:00:46]
>> Brian Holt: Now this is a relatively pointless action. I don't know why you wanna transform an array of cities into an array of 5s, but you can [LAUGH]
>> Speaker 2: How would that affect memory though, because it could be off like two arrays and take more space.
>> Brian Holt: In general, that won't be a problem.

[00:01:08]
>> Brian Holt: I would say it's gonna create and trash a bunch of arrays. That's the nature of the beast. However, you're gonna have to work in pretty large volumes for that to make any difference.
>> Brian Holt: So that's something to check out. Again, Kyle Simpson has another course, as well as Brian Lonsdorf on Frontend Masters on functional programming that are phenomenal.

[00:01:36]
If this peaks your interest in learning to code like this like it does for me, definitely worth checking out, and getting more familiar with. 4-H and math or just like the tip of the iceberg there.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now