featured

Mapping data for fun and profit: Part 2 of the Code Fellows “Mastering Arrays” series

Arrays are an amazing way to store lists of data. But let’s be honest, they’re not always easy to work with… especially when the array is made up of complex objects, and you’re being asked to deliver just a sliver of it. Fear not, .map() to the rescue!

JavaScript gives us an incredibly simple way to safely shape the data in an array, or even reconfigure it completely for a particular use case.

What is the JS Array Map Method?

As per MDN:

Array.prototype.map() : creates a new array populated with the results of calling a provided function on every element in the calling array.

That means we can transmogrify every individual element in an array with a custom transformation, to get a new array full of just as many items, but looking like we want them to look. Great!

How do I use it?

Let’s see it in action!

Next PostPrevious Post

About the Author