var arr = [3,48,66,71,99,101,120,151,188,209]; function searching(arr,target) { var start=0, end=arr.length-1, midIndex, midValue; while(start <= end) { midIndex = Math.floor((start + end) / 2); midValue = arr[midIndex]; if(target === midValue) { return midIndex; }else if(target < midValue) { end = midIndex - 1; }else { start = midIndex + 1; } } return -1; } document.write(searching(arr,120));