shinnn / arr-indexes-of

Like Array#indexOf but return all indexes

Home Page:https://runkit.com/npm/arr-indexes-of

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

arr-indexes-of

npm version Github Actions codecov

Like Array#indexOf(), but return all indexes instead of the first one

import arrIndexesOf from 'arr-indexes-of';

arrIndexesOf(['a', 'a', 'a'], 'a'); //=> [0, 1, 2]
arrIndexesOf(['5', 5, 15, 'five', 5], 5); //=> [1, 4]

Almost the same module as indexes-of, but:

  • only supports Array by design
    • throws TypeError when it takes a String
  • supports optional fromIndex parameter

Installation

Use npm.

npm install arr-indexes-of

API

import arrIndexesOf from 'arr-indexes-of';

arrIndexesOf(array, searchValue [, fromIndex])

array: Array
searchValue: any type (value to search for)
fromIndex: integer (index in the string where to begin searching)
Return: Array

arrIndexesOf(['A', 'B', 'C', '-', 'A', 'B', 'C'], 'A'); //=> [0, 4]
arrIndexesOf(['A', 'B', 'C', '-', 'A', 'B', 'C'], 'A', 4); //=> [4]

Related project

str-indexes-of - String#indexOf() version

License

ISC License © 2018 - 2019 Watanabe Shinnosuke

About

Like Array#indexOf but return all indexes

https://runkit.com/npm/arr-indexes-of

License:ISC License


Languages

Language:JavaScript 94.7%Language:HCL 5.3%