多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## indexOf + [link](./indexOf "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L6047 "View in source.") + [npm](https://www.npmjs.com/package/lodash.indexof "See the npm package.") ``` _.indexOf(array, value, [fromIndex=0]) ``` 根据 value 使用 SameValueZero 等值比较返回数组中首次匹配的 index, 如果 fromIndex 为负值,将从数组尾端索引进行匹配,如果将 fromIndex 设置为 true,将使用更快的二进制检索机制。 ### 参数 1. array (Array) 要检索的数组 2. value (\*) 要检索的值 3. [fromIndex=0] (number) 需要检索的起始位置,如果为 true 将使用二进制检索方式。 ### 返回值 (number) 返回匹配值的index,否则返回 -1。 ### 示例 ``` _.indexOf([1, 2, 1, 2], 2); // => 1 // 使用了 `fromIndex` _.indexOf([1, 2, 1, 2], 2, 2); // => 3 ```