javascript check if array contains at least one element of array code example
Example: nodejs check if array has at least 1 value
/**
* This function checks if the passed param is an array and if it has at least 1 element.
*
* @name exists
* @param {array} input Likely an array but possible for other data types, the data that needs to be checked.
* @return {boolean} true: input param is an array and has at least 1 element, false: input param is not an array or is an array but with no elements.
*/
Array.exists = input => { return Array.isArray(input) && input.some(e => e) }
// Usage
Array.exists([]) // false
Array.exists(`Hello World`)// false
Array.exists([`Hello World`]) // true