Insert in Array





Also use data.splice(2,0,99)

To Visualize: Copy code and test Click Here

Code


    let data = [11,22,33,44,55,66,77,88,99]

    let newEl = 111;
    let position = 2;
    
    for(let i=data.length-1; i>=0; i--){
      if(i>=position){
        data[i+1]=data[i]
        if(i==position){
          data[i]=newEl;
          break;
        }
      }
    }
    console.log(data)