Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
d037b79dcThis file is pinned to the selected release. Download the original to open it in your design tool.
/**
* Return the Nth element of the given array.
*
* @param {*} array - anything
* @param {number} index - index of the element to return
* @returns {*} Nth element of the array, or undefined
*
* @alias module:array-utils.nth
* @function
*
* @example
* let value = nth([1], 2) // returns undefined
* let value = nth([1, 2, 3, 4, 5], 3) // returns 4
*/
export const nth = (array, index) => {
if (!Array.isArray(array) || array.length < index) {
return undefined
}
return array[index]
}