I am trying to increment the numbers in the array
var myArray = [1, 2, 3, 4];
I try to use
for (var i = 0; i < myArray.length; i++){
myArray[i] + 1;
}
but that doesn't seem to do anything :( please help
You can use map()
which will make it quite clean:
var arr = [1,2,3,4];
arr = arr.map(function(val){return ++val;});
console.log(arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With