I attempted to increment each element of my array by one, but was having trouble. Here is what I tried:
myArray=[1,2,3]
myArray.map(a=>a+=1) // also tried a++ and a=a+1
console.log(myArray) // returns [ 1 , 2 , 3 ]
Unfortunately, this method did not work for me...
So I decided to take a different approach:
myArray=[1,2,3]
mySecondArray=[]
myArray.map(a=>mySecondArray.push(a+1))
console.log(mySecondArray) // returns [ 2, 3, 4 ]
Surprisingly, the second method worked perfectly fine. However, I am still puzzled as to why the first method failed. Can you provide an explanation?