str-indexes-of
v1.0.4
Published
Like String#indexOf() but return all indexes
Downloads
2
Maintainers
Readme
str-indexes-of
Like String#indexOf()
, but return all indexes instead of the first one
import strIndexesOf from 'str-indexes-of';
strIndexesOf('aaa', 'a'); //=> [0, 1, 2]
strIndexesOf('ffoofffofofofofofffooffoo', 'foo'); //=> [1, 18, 22]
Almost the same module as indexes-of, but:
- only supports
String
explicitly- throws
TypeError
when it takes anArray
- throws
- supports optional
fromIndex
parameter - disallows empty search value
Installation
npm install str-indexes-of
API
import strIndexesOf from 'str-indexes-of';
strIndexesOf(str, searchValue [, fromIndex])
str: string
searchValue: string
(value to search for)
fromIndex: number
(index in the string where to begin searching)
Return: Array
of string
strIndexesOf('ABC-ABC', 'A'); //=> [0, 4]
strIndexesOf('ABC-ABC', 'A', 4); //=> [4]
Related project
arr-indexes-of - Array#indexOf()
version