isArr
isArr(variable)
isArr(variable)Determines whether the provided variable is an array by utilizing the Array.isArray() method.
Arguments
variable(any): The variable to check if it is an array.
Returns
(boolean): Returnstrueif the variable is an array,falseotherwise.
Example
typescript
import { isArr } from 'check-engineering/ts-utils';
console.log(isArr([1, 2, 3])); // => true
console.log(isArr('not an array')); // => falseUsage
typescript
import { isArr } from 'check-engineering/ts-utils';
const arr = [1, 2, 3];
const notArr = 'not an array';
console.log(isArr(arr)); // => true
console.log(isArr(notArr)); // => falseNotes
Ensure the input
variableis checked for being an array usingArray.isArray(variable).This function provides a quick and reliable way to verify if a given variable is an array, aiding in type checking and validation within your TypeScript projects.
Last updated
Was this helpful?