ts-utils
  • Getting Started
  • Contributing
  • Testing
  • Functions
    • Array Methods
      • isArr
      • isArrEmpty
      • pushUniqueValue
      • pushOrUpdate
    • Date Methods
      • toNow
      • formatDate
      • fromNow
    • Number Methods
      • toFixed
      • parseNumber
      • parseFormat
      • addUnit
      • addSeparators
      • formatNumber
      • ensureNumber
      • numberEmptyState
    • Object Methods
      • parseJSON
      • deepClone
      • parseNumValues
      • removeEmptyKeys
      • sanitizeQuery
      • removeKeys
      • renameKey
      • renameKeys
      • sortByKeyLength
      • querylize
      • parseNumericObj
      • reserveKeys
      • hasKeysAndValues
    • String Methods
      • randomStr
      • toUpperCase
      • toLowerCase
      • toFullUrl
      • initials
      • generateUuid
Powered by GitBook
On this page
  • isArrEmpty(arr)
  • Arguments
  • Returns
  • Example
  • Usage
  • Notes

Was this helpful?

  1. Functions
  2. Array Methods

isArrEmpty

isArrEmpty(arr)

Determines if the provided array contains any elements. It does this by comparing the array's length property to zero. If the length is zero, the function returns true, indicating that the array is empty. Otherwise, it returns false.

Arguments

  • arr (any[]): The array to check for emptiness.

Returns

  • (boolean): Returns true if the array is empty, false otherwise.

Example

typescript
import { isArrEmpty } from 'check-engineering/ts-utils';

console.log(isArrEmpty([])); // => true
console.log(isArrEmpty([1, 2, 3])); // => false

Usage

typescript
import { isArrEmpty } from 'check-engineering/ts-utils';

const emptyArr = [];
const nonEmptyArr = [1, 2, 3];

console.log(isArrEmpty(emptyArr)); // => true
console.log(isArrEmpty(nonEmptyArr)); // => false

Notes

  • The isArrEmpty function provides a straightforward way to determine if an array contains any elements, aiding in conditional logic and array handling within TypeScript projects.

  • Ensure the input arr is an array (any[]) to accurately check for emptiness using the array's length property.

PreviousisArrNextpushUniqueValue

Last updated 11 months ago

Was this helpful?