UNPKG

@extra-array/search-value

Version:
61 lines (46 loc) 1.94 kB
Finds first index of a value. [:package:](https://www.npmjs.com/package/@extra-array/search-value) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/search-value) [:vhs:](https://asciinema.org/a/339820) [:moon:](https://www.npmjs.com/package/@extra-array/search-value.min) [:scroll:](https://unpkg.com/@extra-array/search-value/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Alternatives: [searchValue], [searchValueRight], [searchValueAll].<br> > Similar: [search], [scan], [find]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.searchValue(x, v, [fc], [fm]); // x: an array // v: search value // fc: compare function (a, b) // fm: map function (v, i, x) // → index of value, -1 if not found ``` ```javascript const array = require("extra-array"); var x = [1, 2, 3, 2, 5]; array.searchValue(x, 2); // 1 ^ var x = [1, -2, 3, 2, 5]; array.searchValue(x, 2, (a, b) => Math.abs(a) - Math.abs(b)); // 1 ^ var x = [1, -2, 3, 2, 5]; array.searchValue(x, 2, null, v => Math.abs(v)); // 1 ^ ``` <br> <br> ## References - [List-Extra.elemIndex: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#elemIndex) - [iterable-binsearch: @krisselden](https://www.npmjs.com/package/iterable-binsearch) - [binarysearch: @soldair](https://www.npmjs.com/package/binarysearch) [searchValue]: https://github.com/nodef/extra-array/wiki/searchValue [searchValueRight]: https://github.com/nodef/extra-array/wiki/searchValueRight [searchValueAll]: https://github.com/nodef/extra-array/wiki/searchValueAll [search]: https://github.com/nodef/extra-array/wiki/search [scan]: https://github.com/nodef/extra-array/wiki/scan [find]: https://github.com/nodef/extra-array/wiki/find