How to create a binary search with recursion

I am attempting to write a “binary search” which I’ve never done before. The code below does not work when the value searched for is 6 or 2 and I want to know what I am doing wrong and how to remedy it. EDIT To explain what it is suppose to do (based on my understanding) a binary search requires that an array is already sorted, it then looks for the mid-point index of an array. For example, if an array had nine indexes (0-8)the the mid point would be index 4. The algorithm then determines if that mid point

Improve speed of my binary search algorithm

I have written a binary search algorithm in JavaScript: I wanted to ask if I can improve this algorithm to search faster or if some mistake is made here? EDIT: thank you guys for your help, this solution should work correctly now: Answer You are taking values as indices. If you take greater values than indices, you see your codes does not work. Instead, you could take the index of middle for left or rightif not found.