Merge Two Array in While Loop

Result

To Visualize: Copy code and test Click Here

Code


      let data1 = [11,99,33,44,55,888];
      let data2 = [6,66,22,77,88,99];
      let data = [];
      let d1=0;
      let d2=0;
      let d=0;

      while(d1<data1.length && d2<data2.length){
        if(data1[d1]<data2[d2])
        {
          data[d]=data1[d1];
          d1++;
        }else{
          data[d]=data2[d2];
          d2++;
        }
        d++;
      }

      while(d1<data1.length){
        data[d]=data1[d1]
        d1++;
        d++;
      }
      
      console.log(data)