mid-index-of
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

The midIndexOf method returns the first index at which a given element can be found in the array, or -1 if it is not present.

Specially, this method will search from the middle index, and go to left and right to find target element.

syntax

midIndexOf(array, searchElement, startIndex);

startIdex is optional, and default is half the length of the array.

example

import midIndexOf from 'mid-index-of';

midIndexOf(['a', 'b', 'c', 'd', 'e', 'f'], 'e', 1);
// result: 1
// Actually, it will search with snake path: b -> c -> a -> d -> e

Readme

Keywords

Package Sidebar

Install

npm i mid-index-of

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.09 kB

Total Files

6

Last publish

Collaborators

  • frstar