{"_id":"utils-indexof","_rev":"4087192","name":"utils-indexof","description":"Returns the first index at which a given element can be found.","dist-tags":{"latest":"1.0.0"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"time":{"modified":"2025-12-02T22:11:48.000Z","created":"2016-03-01T22:04:32.831Z","1.0.0":"2016-03-01T22:04:51.340Z","0.0.0":"2016-03-01T22:04:32.831Z"},"users":{},"author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"repository":{"type":"git","url":"git://github.com/kgryte/utils-indexof.git"},"versions":{"1.0.0":{"name":"utils-indexof","version":"1.0.0","description":"Returns the first index at which a given element can be found.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"if [ \"${TRAVIS}\" ]; then npm run test-ci; else npm run test-local; fi","test-local":"tape \"./test/*.js\" | tap-spec","test-ci":"npm run test-local && xvfb-run npm run test-browsers","test-cov":"istanbul cover --dir ./reports/coverage --report lcov tape -- \"./test/*.js\"","test-browsers":"browserify ./test/*.js | testling | tap-spec","coverage":"istanbul cover --dir ./reports/codecov/coverage --report lcovonly tape -- \"./test/*.js\" && cat ./reports/codecov/coverage/lcov.info | codecov && rm -rf ./reports/codecov"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-indexof.git"},"keywords":["utilities","utility","utils","util","indexof","array","object","array-like","string","search","find","locate","index","polyfill","ponyfill","arr","str","obj"],"bugs":{"url":"https://github.com/kgryte/utils-indexof/issues"},"dependencies":{"validate.io-array-like":"^1.0.1","validate.io-integer-primitive":"^1.0.0"},"devDependencies":{"browserify":"13.x.x","codecov":"1.x.x","istanbul":"^0.4.1","jshint":"2.x.x","jshint-stylish":"2.x.x","tap-spec":"4.x.x","tape":"4.x.x","testling":"1.x.x"},"testling":{"files":["test/*.js"],"browsers":["iexplore/6.0..latest","firefox/3.0..latest","firefox/nightly","chrome/4.0..latest","chrome/canary","opera/10.0..latest","opera/next","safari/4.0..latest","ipad/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"license":"MIT","gitHead":"e4922b28266738302347121d7ca6c5bc61d0da6b","homepage":"https://github.com/kgryte/utils-indexof#readme","_id":"utils-indexof@1.0.0","_shasum":"20feabf09ef1018b523643e8380e7bc83ec61b5c","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.3","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"dist":{"shasum":"20feabf09ef1018b523643e8380e7bc83ec61b5c","size":4016,"noattachment":false,"key":"/utils-indexof/-/utils-indexof-1.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-indexof/download/utils-indexof-1.0.0.tgz"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/utils-indexof-1.0.0.tgz_1456869890805_0.4509516255930066"},"directories":{},"publish_time":1456869891340,"_hasShrinkwrap":false,"_cnpm_publish_time":1456869891340,"_cnpmcore_publish_time":"2021-12-17T01:24:50.313Z"},"0.0.0":{"name":"utils-indexof","version":"0.0.0","description":"Returns the first index at which a given element can be found.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"}],"scripts":{"test":"if [ \"${TRAVIS}\" ]; then npm run test-ci; else npm run test-local; fi","test-local":"tape \"./test/*.js\" | tap-spec","test-ci":"npm run test-local && xvfb-run npm run test-browsers","test-cov":"istanbul cover --dir ./reports/coverage --report lcov tape -- \"./test/*.js\"","test-browsers":"browserify ./test/*.js | testling | tap-spec","coverage":"istanbul cover --dir ./reports/codecov/coverage --report lcovonly tape -- \"./test/*.js\" && cat ./reports/codecov/coverage/lcov.info | codecov && rm -rf ./reports/codecov"},"main":"./lib","repository":{"type":"git","url":"git://github.com/kgryte/utils-indexof.git"},"keywords":["utilities","utility","utils","util","indexof","array","object","array-like","string","search","find","locate","index","polyfill","ponyfill","arr","str","obj"],"bugs":{"url":"https://github.com/kgryte/utils-indexof/issues"},"dependencies":{"validate.io-array-like":"^1.0.1","validate.io-integer-primitive":"^1.0.0"},"devDependencies":{"browserify":"13.x.x","codecov":"1.x.x","istanbul":"^0.4.1","jshint":"2.x.x","jshint-stylish":"2.x.x","tap-spec":"4.x.x","tape":"4.x.x","testling":"1.x.x"},"testling":{"files":["test/*.js"],"browsers":["iexplore/6.0..latest","firefox/3.0..latest","firefox/nightly","chrome/4.0..latest","chrome/canary","opera/10.0..latest","opera/next","safari/4.0..latest","ipad/6.0..latest","iphone/6.0..latest","android-browser/4.2..latest"]},"license":"MIT","gitHead":"9ac063898f35bb526c5ee002317043c746f7d4d4","homepage":"https://github.com/kgryte/utils-indexof#readme","_id":"utils-indexof@0.0.0","_shasum":"6cb41983323eb3b0cc8ff2597aefca8df98f36f1","_from":".","_npmVersion":"2.14.7","_nodeVersion":"4.2.3","_npmUser":{"name":"kgryte","email":"kgryte@gmail.com"},"dist":{"shasum":"6cb41983323eb3b0cc8ff2597aefca8df98f36f1","size":4018,"noattachment":false,"key":"/utils-indexof/-/utils-indexof-0.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/utils-indexof/download/utils-indexof-0.0.0.tgz"},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"}],"_npmOperationalInternal":{"host":"packages-13-west.internal.npmjs.com","tmp":"tmp/utils-indexof-0.0.0.tgz_1456869872308_0.038668237160891294"},"directories":{},"publish_time":1456869872831,"_hasShrinkwrap":false,"_cnpm_publish_time":1456869872831,"_cnpmcore_publish_time":"2021-12-17T01:24:50.515Z"}},"readme":"indexOf\n===\n[![NPM version][npm-image]][npm-url] [![Build Status][build-image]][build-url] [![Coverage Status][coverage-image]][coverage-url] [![Dependencies][dependencies-image]][dependencies-url]\n\n> Returns the first index at which a given element can be found.\n\n\n## Installation\n\n``` bash\n$ npm install utils-indexof\n```\n\n\n## Usage\n\n``` javascript\nvar indexOf = require( 'utils-indexof' );\n```\n\n#### indexOf( arr, searchElement[, fromIndex] )\n\nReturns the first index at which a given element can be found.\n\n``` javascript\nvar arr = [ 4, 3, 2, 1 ];\n\nvar idx = indexOf( arr, 3 );\n// returns 1\n```\n\nIf a `searchElement` is __not__ present in an input `array`, the `function` returns `-1`.\n\n``` javascript\nvar arr = [ 4, 3, 2, 1 ];\n\nvar idx = indexOf( arr, 5 );\n// returns -1\n```\n\nBy default, the implementation searches an input `array` beginning from the first element. To start searching from a different element, specify a `fromIndex`.\n\n``` javascript\nvar arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n\nvar idx = indexOf( arr, 2, 3 );\n// returns 5\n```\n\nIf a `fromIndex` exceeds the input `array` length, the `function` returns `-1`.\n\n``` javascript\nvar arr = [ 1, 2, 3, 4, 2, 5 ];\n\nvar idx = indexOf( arr, 2, 10 );\n// returns -1\n```\n\nIf a `fromIndex` is less than `0`, the starting index is determined relative to the last index (with the last index being equivalent to `fromIndex = -1`).\n\n``` javascript\nvar arr = [ 1, 2, 3, 4, 5, 2, 6, 2 ];\n\nvar idx = indexOf( arr, 2, -4 );\n// returns 5\n\nidx = indexOf( arr, 2, -1 );\n// returns 7\n```\n\nIf `fromIndex` is less than `0` __and__ its absolute value exceeds the input `array` length, the `function` searches the entire input `array`.\n\n``` javascript\nvar arr = [ 1, 2, 3, 4, 5, 2, 6 ];\n\nvar idx = indexOf( arr, 2, -10 );\n// returns 1\n```\n\nThe first argument is not limited to `arrays`, but may be any [array-like][validate.io-array-like] `object`.\n\n``` javascript\nvar str = 'bebop';\n\nvar idx = indexOf( str, 'o' );\n// returns 3\n```\n\n\n## Notes\n\n* \tSearch is performed using __strict equality__ comparison. Thus,\n\t\n\t``` javascript\n\tvar arr = [ 1, [1,2,3], 3 ];\n\n\tvar idx = indexOf( arr, [1,2,3] );\n\t// returns -1\n\t```\n\n*\tThis implementation is __not__ [ECMAScript Standard][ecma-262] compliant. Notably, the [standard][ecma-262] specifies that an `array` be searched by calling `hasOwnProperty` (thus, for most cases, incurring a performance penalty), and the [standard][ecma-262] does __not__ accommodate a `searchElement` equal to `NaN`. In this implementation, the following is possible:\n\n\t``` javascript\n\t// Locate the first element which is NaN...\n\tvar arr = [ 1, NaN, 2, NaN ];\n\n\tvar idx = indexOf( arr, NaN );\n\t// returns 1\n\n\t// Prototype properties may be searched as well...\n\tfunction Obj() {\n\t\tthis[ 0 ] = 'beep';\n\t\tthis[ 1 ] = 'boop';\n\t\tthis[ 2 ] = 'woot';\n\t\tthis[ 3 ] = 'bap';\n\t\tthis.length = 4;\n\t\treturn this;\n\t}\n\tObj.prototype[ 2 ] = 'bop';\n\n\tvar obj = new Obj();\n\t\n\tidx = indexOf( obj, 'bop' );\n\t// returns -1\n\n\tdelete obj[ 2 ];\n\n\tidx = indexOf( obj, 'bop' );\n\t// returns 2\n\t```\n\n\n## Examples\n\n``` javascript\nvar indexOf = require( 'utils-indexof' );\n\nvar arr;\nvar obj;\nvar str;\nvar idx;\nvar i;\n\n// Arrays...\narr = new Array( 10 );\nfor ( i = 0; i < arr.length; i++ ) {\n\tarr[ i ] = i * 10;\n}\nidx = indexOf( arr, 40 );\n\nconsole.log( idx );\n// returns 4\n\n\n// Array-like objects...\nobj = {\n\t'0': 'beep',\n\t'1': 'boop',\n\t'2': 'bap',\n\t'3': 'bop',\n\t'length': 4\n};\n\nidx = indexOf( obj, 'bap' );\n\nconsole.log( idx );\n// returns 2\n\n\n// Strings...\nstr = 'beepboopbop';\n\nidx = indexOf( str, 'o' );\n\nconsole.log( idx );\n// returns 5\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n---\n## Tests\n\n### Unit\n\nThis repository uses [tape][tape] for unit tests. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul][istanbul] as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n### Browser Support\n\nThis repository uses [Testling][testling] for browser testing. To run the tests in a (headless) local web browser, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-browsers\n```\n\nTo view the tests in a local web browser,\n\n``` bash\n$ make view-browser-tests\n```\n\n<!-- [![browser support][browsers-image]][browsers-url] -->\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT).\n\n\n## Copyright\n\nCopyright &copy; 2016. Athan Reines.\n\n\n[npm-image]: http://img.shields.io/npm/v/utils-indexof.svg\n[npm-url]: https://npmjs.org/package/utils-indexof\n\n[build-image]: http://img.shields.io/travis/kgryte/utils-indexof/master.svg\n[build-url]: https://travis-ci.org/kgryte/utils-indexof\n\n[coverage-image]: https://img.shields.io/codecov/c/github/kgryte/utils-indexof/master.svg\n[coverage-url]: https://codecov.io/github/kgryte/utils-indexof?branch=master\n\n[dependencies-image]: http://img.shields.io/david/kgryte/utils-indexof.svg\n[dependencies-url]: https://david-dm.org/kgryte/utils-indexof\n\n[dev-dependencies-image]: http://img.shields.io/david/dev/kgryte/utils-indexof.svg\n[dev-dependencies-url]: https://david-dm.org/dev/kgryte/utils-indexof\n\n[github-issues-image]: http://img.shields.io/github/issues/kgryte/utils-indexof.svg\n[github-issues-url]: https://github.com/kgryte/utils-indexof/issues\n\n[tape]: https://github.com/substack/tape\n[istanbul]: https://github.com/gotwarlost/istanbul\n[testling]: https://ci.testling.com\n\n[ecma-262]: http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.indexof\n[validate.io-array-like]: https://github.com/validate.io/array-like\n","_attachments":{},"homepage":"https://github.com/kgryte/utils-indexof#readme","bugs":{"url":"https://github.com/kgryte/utils-indexof/issues"},"license":"MIT"}