> For the complete documentation index, see [llms.txt](https://alex-myznikov.gitbook.io/adsjs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alex-myznikov.gitbook.io/adsjs/api/searches/binarysearch.md).

# Binary search

### binarySearch()

```typescript
/**
 * Finds item in sorted array greater than or equal to the specified target.
 *
 * @param arr Array to search in.
 * @param target Search target.
 * @param from Index to start search from (inclusive). Will start from 0 by default.
 * @param to Index to stop search at (exclusive). Will examine the whole array by default.
 * @param compare Comparison function. Items are compared as numbers by default.
 * @returns Object with 'index' field representing an item the search has stopped at
 * and 'exact' field telling whether the target was matched exactly.
 */
function binarySearch<T, K = T>(
  arr: T[],
  target: K,
  from?: number,
  to?: number,
  compare: CompareFunc<T, K> = compareAsNumbers,
): { index: number, exact: boolean };
```

Finds item in sorted array greater than or equal to the specified target.
