I just would like to understand why this works:
let newArray = [0,1,2,3].map(elem => elem + 1);
console.log(newArray);
and this doesn't:
let newArray = [0,1,2,3].map(elem => elem++);
console.log(newArray);
That is related to the ++ operator.
return elem++ means return the original value of elem, and after that, elem value will be increased.
To fix this, use ++elem.
Refer to ++ operator.
let newArray = [0,1,2,3].map(elem => ++elem);
console.log(newArray);
elem++iselem.