@writetome51/array-get-by-index
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

getByIndex(index, array): any

Returns 1 item from array, accessed by its index.
So why use this instead of simply writing array[index]? This lets you use a
negative index, and will also trigger an error if the index doesn't exist in the array.

Examples

let arr = [1,2,3,4,5,6,7];

getByIndex(-1, arr); // --> 7

getByIndex(3, arr); // --> 4

getByIndex(-7, arr); // --> 1

getByIndex(-8, arr);
// Error: "The entered index is not valid.  Whether positive or negative,
//          it exceeds the index range of the array."

Installation

npm i @writetome51/array-get-by-index

Loading

import { getByIndex } from '@writetome51/array-get-by-index';

Package Sidebar

Install

npm i @writetome51/array-get-by-index

Weekly Downloads

6

Version

2.0.1

License

MIT

Unpacked Size

2.92 kB

Total Files

5

Last publish

Collaborators

  • writetome51