var arr = [2,5,6,7,8,9,12,23,34,55,67,89,209] function seaching(array,target){ let start = 0,end = array.length - 1,middle,element while(start <= end){ middle = Math.floor((start + end) / 2) element = array[middle] if(target === element){ return middle }else if(target < element){ end = middle - 1 }else{ start = middle + 1 } } return -1 } console.log(seaching(arr,12))