1.0.1 • Published 6 years ago

find-item-in-array v1.0.1

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

Methods:

thFromEndOfArray

This method finds N-th item from end of array and returns its. If you require N-th more than length of array, then it returns first item.

import find from 'find-item-in-array'
const array = ['a', 'b', 'c', 'd', 'e', 'f']
find(2).thFromEndOfArray(array) // return "e"
find(1).thFromEndOfArray(array) // return "f"
find(20).thFromEndOfArray(array) // return "a"
thFromStartOfArray

This method finds N-th item from start of array and returns its. If you require N-th more than length of array, then it returns last item.

import find from 'find-item-in-array'
const array = ['a', 'b', 'c', 'd', 'e', 'f']
find(5).thFromStartOfArray(array) // return "e"
find(1).thFromStartOfArray(array) // return "a"
find(20).thFromStartOfArray(array) // return "f"