Add element in specific index in array

const arr = ["A", "B", "X", "Y", "Z"];

arr.splice(2, 0, "C", "D");

console.log(arr);

output

["A","B","C","D","X","Y","Z"]

Comments