3.1.2 • Published 5 years ago

index-of-x v3.1.2

Weekly downloads
315
License
MIT
Repository
github
Last release
5 years ago

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.
ParamTypeDescription
arrayArrayThe array to search.
searchElement*Element to locate in the array.
fromIndexnumberThe 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).
extendstringExtension type: SameValue or SameValueZero.

Example

import indexOf from 'index-of-x';

const subject = [2, 3, undefined, true, 'hej', null, 2, false, 0, -0, NaN];

// Standard mode, operates just like `Array.prototype.indexOf`.
console.log(indexOf(subject, null)); // 5
console.log(indexOf(subject, '2')); // -1
console.log(indexOf(subject, NaN)); // -1
console.log(indexOf(subject, -0)); // 8
console.log(indexOf(subject, 2, 2)); //6

// `SameValueZero` mode extends `indexOf` to match `NaN`.
console.log(indexOf(subject, null, 'SameValueZero')); // 5
console.log(indexOf(subject, '2', 'SameValueZero')); // -1
console.log(indexOf(subject, NaN, 'SameValueZero')); // 10
console.log(indexOf(subject, -0, 'SameValueZero')); // 8
console.log(indexOf(subject, 2, 2, 'SameValueZero')); //6

// `SameValue` mode extends `indexOf` to match `NaN` and signed `0`.
console.log(indexOf(subject, null, 'SameValue')); // 5
console.log(indexOf(subject, '2', 'SameValue')); // -1
console.log(indexOf(subject, NaN, 'SameValue')); // 10
console.log(indexOf(subject, -0, 'SameValue')); // 9
console.log(indexOf(subject, 2, 2, 'SameValue')); //6
3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.18

5 years ago

3.0.17

5 years ago

3.0.16

5 years ago

3.0.15

5 years ago

3.0.14

5 years ago

3.0.13

5 years ago

3.0.12

5 years ago

3.0.11

5 years ago

3.0.10

5 years ago

3.0.9

5 years ago

3.0.8

5 years ago

3.0.7

5 years ago

3.0.6

5 years ago

3.0.5

5 years ago

3.0.4

5 years ago

3.0.3

5 years ago

3.0.2

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.3.0

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.3

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.10.0

7 years ago

1.9.0

7 years ago

1.8.0

7 years ago

1.7.0

7 years ago

1.5.0

7 years ago

1.4.0

7 years ago

1.3.0

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago