Arrays.findIndices()
Syntax
Overload 1
function findIndices<T>(array: T[], predicate: (object: T) => boolean): number[]
Returns the indices for all elements that match the predicate. This function is parallel to Array.prototype.findIndex(), but whereas findIndex() only returns the first matching index, this function returns all of them.
| Parameters | |
array
|
The array to filter. |
predicate
|
A predicate that returns |
Overload 2
function findIndices<T>(array: T[], object: T): number[]
Returns the indices for all elements equal to object. This function is parallel to Array.prototype.indexOf(), but whereas indexOf() only returns the first matching index, this function returns all of them.
| Parameters | |
array
|
The array to filter. |
object
|
An object of the array’s type that may or may not be included in the array itself. |
Example
import { Arrays } from 'potence';
const array = [0, 1, 2, 2, 4, 8, 10, 12];
Arrays.findIndices(array, 2); // -> [2, 3]
Arrays.findIndices(array, value => value % 4 === 0);
// -> [4, 5, 7]