0
What is mapping in JS
I am having difficulties understanding map() in js
6 ответов
+ 3
Okay, so map() method is used to map over the array and return something for each element in it.
for example
let arr = [1,2,3,4,5];
console.log(arr);
arr = arr.map((val) => val + 1);
console.log(arr);
+ 4
Yes, map function takes a callback function as argument with takes value which is equal to element each iteration
So 1 will be added to each of element like 1 becomes 2 and 2 is 3.
+ 4
While Rick's answer is good, please let me provide more context :
https://code.sololearn.com/WwyR3SGoozeD/?ref=app
Firstly, map does not change the original array. It returns a new array.
Secondly, the callback can be explicitly declared and with function keyword.
Thirdly, the callback can take up to 3 arguments, namely item, index and the array itself.
+ 1
Are you talking about Array method map()?
0
yes sir
0
Thanks sir, buh i am still a kindda confuse here. according to the code you wrote, 1 will be added to all the elements in the array?