If I have this array ['Jan', 'March', 'April', 'June']. How to replace 'April' with 'newVal' and keep all other elements unchanged.
I tried
const months = ['Jan', 'March', 'April', 'June'];
months.splice(3, 1, 'newVal');
console.log(months);
I want it to return ['Jan', 'March', 'newVal', 'June']
but it returns ["Jan", "March", "April", "newVal"]
0. So the index should be2