1arr.splice(index, 0, item);
2//explanation:
3inserts "item" at the specified "index",
4deleting 0 other items before it
1const items = [1, 2, 3, 4, 5]
2
3const insert = (arr, index, newItem) => [
4 // part of the array before the specified index
5 ...arr.slice(0, index),
6 // inserted item
7 newItem,
8 // part of the array after the specified index
9 ...arr.slice(index)
10]
11
12const result = insert(items, 1, 10)
13
14console.log(result)
15// [1, 10, 2, 3, 4, 5]