index-of-x
An extended ES6 indexOf.
Version: 2.3.0
Author: Xotic750 Xotic750@gmail.com
License: MIT
Copyright: Xotic750
module.exports(array, searchElement, [fromIndex], [extend])
⇒ number
⏏
This method returns the first index at which a given element can be found
in the array, or -1 if it is not present.
Kind: Exported function
Returns: number
- Returns index of found element, otherwise -1.
Throws:
TypeError
If array
is null
or undefined
.
Param | Type | Description |
---|
array | Array | The array to search. |
searchElement | * | Element to locate in the array . |
[fromIndex] | number | The index to start the search at. If the index is greater than or equal to the array's length, -1 is returned, which means the array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of the array. Note: if the provided index is negative, the array is still searched from front to back. If the calculated index is less than 0, then the whole array will be searched. Default: 0 (entire array is searched). |
[extend] | string | Extension type: SameValue or SameValueZero . |
Example
import indexOf from 'index-of-x';
const subject = [2, 3, undefined, true, 'hej', null, 2, false, 0, -0, NaN];
console.log(indexOf(subject, null));
console.log(indexOf(subject, '2'));
console.log(indexOf(subject, NaN));
console.log(indexOf(subject, -0));
console.log(indexOf(subject, 2, 2));
console.log(indexOf(subject, null, 'SameValueZero'));
console.log(indexOf(subject, '2', 'SameValueZero'));
console.log(indexOf(subject, NaN, 'SameValueZero'));
console.log(indexOf(subject, -0, 'SameValueZero'));
console.log(indexOf(subject, 2, 2, 'SameValueZero'));
console.log(indexOf(subject, null, 'SameValue'));
console.log(indexOf(subject, '2', 'SameValue'));
console.log(indexOf(subject, NaN, 'SameValue'));
console.log(indexOf(subject, -0, 'SameValue'));
console.log(indexOf(subject, 2, 2, 'SameValue'));