UNPKG

@extra-array/index-range

Version:

Gets index range of part of array.

53 lines (38 loc) 1.45 kB
Gets index range of part of array. [:package:](https://www.npmjs.com/package/@extra-array/index-range) [:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-array) [:running:](https://npm.runkit.com/@extra-array/index-range) [:vhs:](https://asciinema.org/a/332065) [:moon:](https://www.npmjs.com/package/@extra-array/index-range.min) [:scroll:](https://unpkg.com/@extra-array/index-range/) [:newspaper:](https://nodef.github.io/extra-array/) [:blue_book:](https://github.com/nodef/extra-array/wiki/) > Similar: [index], [indexRange], [size], [isEmpty]. > This is part of package [extra-array]. [extra-array]: https://www.npmjs.com/package/extra-array <br> ```javascript array.indexRange(x, [i], [I]); // x: an array // i: start index (-ve: from right) (0) // I: end index (-ve: from right) (X) // → [start index, end index] ``` ```javascript const array = require("extra-array"); var x = [2, 4, 6, 8]; array.indexRange(x, 1); // [1, 4] array.indexRange(x, 1, -1); // [1, 3] array.indexRange(x, 1, -10); // [1, 1] ``` <br> <br> ## References - [Array.prototype.slice: MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice) [index]: https://github.com/nodef/extra-array/wiki/index [indexRange]: https://github.com/nodef/extra-array/wiki/indexRange [size]: https://github.com/nodef/extra-array/wiki/size [isEmpty]: https://github.com/nodef/extra-array/wiki/isEmpty