JS: Array.prototype.map
xArray.map(f)-
- Apply function to every element of the array.
- Return the new array.
- Original array is not changed.
f is passed 3 args: currentElement currentIndex xArray.
const aa = [3, 4, 5]; const bb = aa.map((x) => (x + 1)); console.log(bb); // [ 4, 5, 6 ] // original is not changed console.log(aa); // [ 3, 4, 5 ] xArray.map(f, thisArg)-
Use thisArg for this (binding) of f. Default to
undefined.// example of using map with second argument function ff(x) { return [x, this]; } console.log([3, 4, 5].map(ff, 9)); // [ [ 3, 9 ], [ 4, 9 ], [ 5, 9 ] ]