Map an array with this props

Map an array with this props
0.0 0

#1

Hi,
I’m struggling with map property, I mean I’m french, and the translation is obscure.
Someone can explain me with an example the meaning in English.
Thanks


#2

It would really help if you could tell us what you understand and which parts confuse you. Array.prototype.map() allows you to provide a function that will transform every element into an array and replace it with the result of that function.


#3

I understood the method and the way to use it, it’s Javascript functionnal.
But it’s more the English I don’t understand.
What’s mean map, I tought it was mean, an us map or Island map.
ex: " in JavaScript and allows you to “map” over an array"


#4

Ah. I’m guessing that the origin of the name “map” comes from the fact the callback function creates what we would call “a one-to-one mapping of values,” meaning for every input there is exactly one predictable output. In the example used on MDN, they are creating squares. In that situation we would say that “two maps to four, three maps to nine,” and so on.


#5

Another way of saying this is:

" in JavaScript and allows you to **iterate** over an array"

#6

I can say, a map is a synonym to iterate?
It helps to understand even if it still obscure :confused:


#7

@ArielLeslie
Mapping word still :confused: me…

EDIT: After reading again, I got it, thanks
Btw, I don’t think we have this expression in French?


#8

I was just trying to get you to understand what “mapping” over an array is like. It is best to read the documentation for what map does. See here.


#9

I think map is best explained with a simple example.

If I created an array as below:

var arr = [1,2,3,4,5];

and then I wanted to created a new array (called newArr) which needed to contain the values of the original array (arr) plus 100, then I could do that with the following code:

var newArr = [];
for (var i = 0; i < arr.length; i++) {
  newArr.push(arr[i]+100);
}

I could also use map to do exactly the same thing:

var newArr = arr.map(function(val) {
  return val + 100;
});

or using the ES6 arrow function syntax as:

var newArr = arr.map(val => val + 100);

All of the above pieces of code create a new array (called newArr) with the following values:

[ 101, 102, 103, 104, 105 ]

#10

I haven’t problem to understand the prototype it self, thanks anyway.


#11

I think that’s a good description. :thumbsup:

I would go just one step further by saying “iterate and change”… because that’s what you usually do with map. You create a new array by iterating over each item and changing it to something new.

Also, the MDN docs are available in French. :slight_smile:


#12

in French, I forgot about this feature :blush: