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:
// ONLINE-RUNNER:browser;
var array = ['a', 'b', 'c'];
var replacement = 'x';
array[array.length - 1] = replacement;
console.log(array); // ['a', 'b', 'x']