EN
JavaScript - replace last item in array
0 points
In this article, we would like to show you how to replace last item in array in JavaScript.
Quick solution:
xxxxxxxxxx
1
var array = ['a', 'b', 'c'];
2
3
var replacement = 'x';
4
5
array[array.length - 1] = replacement;
6
7
console.log(array); // ['a', 'b', 'x']