splice is time complexity O(n); I tried this version instead of splice: which has added space complexity but i think less time complexity.
let arr = [0,1];
arr[5] = 5;
// i need to push numbers into this index only-not to the whole array
// push wont work on a 1d array but will work on 2d array
arr[5] = [[], 5];
// now it is possible to push into this index
arr[5].push(15,125,1035);
// remove the unnecessary empty cell []
arr[5].shift();
console.log(arr) // result [0,1,[5,15,125,1035]]
So is this worse than splice, or better(in terms of time complexity)?
EDIT: this is a bad take of the answer given, my problem was i didn't understand why you couldn't push into an index of an array. when you try: arr = [1,2,3,4] and then arr[1].push(2.5); you would get an error since you try and push into a primitive(number and not an object/array). My mistake was that i thought JS just doesn't allow it.