If you have an empty array, that is an array with 0 length,
single negation with ! returns a misleading boolean.
arr = []
!arr.length // true - because `0` is `false`, `!` negates `false` to `true`
// double negate it for clear boolean
console.log(!!arr?.length, arr?.length); // false 0
Truthy example
arr = ['','','']
// array with values
console.log(!!arr?.length, arr?.length); // true 3
Make sure to check if .length exists with optional chain ?
if (!!arr?.length) console.log(!!arr?.length);
Now you can reliably use .length as a boolean to check for empty arrays.
Note: Double negation has caveats like ESLint's no-extra-boolean-cast
false. The preceding!operator (semantically "not") inverts the boolean totrue.