Socket
Socket
Sign inDemoInstall

index-of-x

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

index-of-x

An extended ES6 indexOf.


Version published
Weekly downloads
588
decreased by-28.29%
Maintainers
1
Weekly downloads
 
Created
Source

Travis status Dependency status devDependency status npm version jsDelivr hits bettercodehub score Coverage Status

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.
[fromIndex]numberThe 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]stringExtension 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

Keywords

FAQs

Package last updated on 28 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc