配列の特定の要素を置換える splice
const ar = [10, 20, 30];
const arr = ["one", "two"];
console.log(arr); // ["one", "two"]
console.log(arr.splice(2, 0, "three", "four")); // []
console.log(arr); // ["one", "two", "three", "four"]
console.log(arr.splice(1, 1, "three", "four")); // ["two"]
console.log(arr); // ["one", "three", "four", "three", "four"]配列.splice(追加位置, 削除数, 追加要素1, 追加要素2,…)
※元の配列が加減される。新しい配列が返るわけでないので注意
戻り値:削除した配列要素
// 戻り値は配列で返ってくるので、戻り値を使う場合には位置指定が必要
console.log(["one","two"].splice(1, 1,)); // ["two"]
console.log(["one","two"].splice(1, 1,)[0]); // "two"