1.1.0 • Published 6 years ago
is-array-of-length v1.1.0
is-array-of-length
Returns true if a value is an array containing the specified number of elements.
Installation
Requires Node.js 6.0.0 or above.
npm i is-array-of-lengthAPI
The module exports a single function.
Parameters
arr(any): What may or may not be an arraylengths(integer or array): One or more integers, each of which represents an acceptable number of items in the array.- Optional: Object argument:
arrays(class, string, or array): One or more classes or names of classes that should be treated as equivalent toArray.
Return Values
trueifarris an array with a length given inlengthsfalseotherwise
Example
const isArrayOfLength = require('is-array-of-length')
isArrayOfLength(['a', 'b'], 2) // true
isArrayOfLength(['a', 'b'], 3) // false
isArrayOfLength(['a', 'b'], [2, 3]) // true
isArrayOfLength('7 chars', 7) // false
// Supports the bind operator
['a', 'b']::isArrayOfLength(2) // true