Steps to get the solution: 1. We have to take two pointers on two arrays and initialize a result array with empty data. 2. If value at first array pointer is less that second array pointer, merge the first array value to the result array and Increment the first array pointer 3. if value at second array pointer less that first array pointer, merge the second array value to result array and Increment the second array pointer 4.If one of the pointer reached at the end of the array, merge the other items in result array. Code:

function mergeSortedArrays(x, y){
  var i=0,j=0,result=[];
  while(i<x.length && j<y.length) {
      if(x[i]<y[j]) {
        result.push(x[i]);
        i++;
      }    
      else if(x[i]>y[j]) {
          result.push(y[j]);
          j++
      }
     else {
	  result.push(x[i]);
	  i++;
	  j++;
       }
  }
  while(i<x.length) {
    result.push(x[i])
	i++;
  }
  while(j<y.length)
  {
    result.push(y[j]);
	j++;
  }
  return result;
}

let arr1= [1,3,5];
let arr2=[2,4,8];
let result = mergeSortedArrays(arr1,arr2);
console.log('result', result); //output : [1,2,3,4,5,8]