Increment and decrement array elements in JavaScript
You can also use increment and decrement operations:
let arr = [1, 2, 3, 4];
arr[0]++;
++arr[1];
arr[2]--;
--arr[3];
console.log(arr); // shows [2, 3, 2, 3]
Create an array with elements 1
,
2
and 3
. Use the ++
operator to increase each array element by one.