How to insert an item into an array at a specific index (JavaScript)
You want the splice function on the native array object. arr.splice(index, 0, item); will insert item into arr at the specified index (deleting 0 items first, that is, it’s just an insert). In this example we will create an array and add an element to it into index 2: var arr = []; arr[0] = … Read more