function insertsInPlace(arr, value) { const len = arr.length; for (let i = len - 1, k = 2 * i; i >= 0; --i, k -= 2) { arr[k] = arr[i]; arr[k + 1] = value; } return arr; } const arr = [2, 3, 4, 5]; insertsInPlace(arr, 1); alert(JSON.stringify(arr));