Skip to content

writetome51/error-if-index-is-negative

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

errorIfIndexIsNegative(index): void

Triggers error if index is negative number, saying "value not found in array".
This function is intended to be called after you've called Array.indexOf(), or any
function that returns a negative number if the value being searched for in the array
was not found. You then pass that resulting index to this function.

Example

let arr = [1,2,3,4];
let index = arr.indexOf(5);
errorIfIndexIsNegative(index);
// "Error:  value not found in array"

Installation

npm install error-if-index-is-negative

Loading

import { errorIfIndexIsNegative } from 'error-if-index-is-negative';

License

MIT

About

Function triggers error if a given index is a negative number, meaning the item was not found in the array

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published