The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

The Array map method

The Array map method

3:02
One very common operation in programming is to iterate through an Array's contents, apply a function to each item, and create a new array containing the results. For example, let's say you wanted to loop through an array of stock objects and select only the name for display on screen. In this lesson we will demonstrate how to use the Array's map method to easily perform this operation with less code than a loop would require.
Watch this lesson now
Avatar
egghead.io

One very common operation in programming is to iterate through an Array's contents, apply a function to each item, and create a new array containing the results. For example, let's say you wanted to loop through an array of stock objects and select only the name for display on screen. In this lesson we will demonstrate how to use the Array's map method to easily perform this operation with less code than a loop would require.

Avatar
Kristofer

Hi, I have a question regarding the symbols object. After the function has run has the values in this object been replaced and only contains the symbols, or does it still contain price and volume?

Avatar
labeeb

Only symbols are in the array.

In reply to Kristofer
Avatar
abhinav reddy

does map,filter and reduce create shallow copy's

In reply to egghead.io
Avatar
Andrejb

A very bad example for beginners. However, master doesn't look anything useful.
Awful example, can't imagine why and for what i pay the money. W3Schools explains better.

Avatar
beckinfonet

Hi,
Could you please explain why:
var symbols = getStockSymbols([
..........])
var is assigned to an array and on line #1 it is function with the same name?

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?