js update value in array code example

Example 1: js insert in array

const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]

months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]

Example 2: javascript switch items in array

var b = list[y];
list[y] = list[x];
list[x] = b;

Example 3: js array modify element

people[0] = "Georgie";