Answers for "js check at least one in array"

2

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
Posted by: Guest on February-17-2021

Code answers related to "js check at least one in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language