JavaScript: map() method

The JavaScript Map method is a method that maps an object of key-value pairs with a function. This is done by iterating over the object’s keys and invoking the function with the corresponding values in order.

var arr = [1,2,3,4,5,6,7,8,9,10];

var newArr = arr.map(function(item, index, array) {
  return item * 2;
});

console.log(newArr); // [ 2,4,6,8,10,12,14,16,18,20 ]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: