1.0.0 • Published 1 year ago

mid-index-of v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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