Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →For a value that is already an array, check whether its length is zero: items.length === 0. If the value might be null, undefined, or not an array at all, guard or validate it before reading length.
Check a known array with length
JavaScript arrays expose a numeric length property. An empty array has a length of zero, so this is the direct check:
const isEmpty = items.length === 0;
const hasItems = items.length > 0;
Use strict equality (===) for the empty check. TypeScript documents array types and properties in its Object Types handbook.
Why items === [] does not work
Do not compare an array to a newly created empty array. Arrays are objects, and equality compares their references—not whether they contain the same elements. The newly written [] is a different array from items, so items === [] is false even when items has no elements. TypeScript 4.8 documents this comparison as always false in its release notes.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Handle arrays that may be null or undefined
If the declared type allows either nullish value, check that the value exists before accessing length:
if (items != null && items.length === 0) {
// items is present and empty
}
The items != null check excludes both null and undefined. TypeScript narrows the type after this guard, allowing the property access. The Narrowing handbook explains nullish checks and why broad truthiness checks can be inappropriate when a union includes other valid falsy values.
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
Validate uncertain runtime input with Array.isArray
A TypeScript type does not by itself establish the shape of data received at runtime, such as an external input. Check the value first when it may not be an array:
if (Array.isArray(value)) {
const isEmpty = value.length === 0;
}
Inside the condition, value is known to be an array, so it is safe to inspect length. TypeScript documents this use of Array.isArray for values with multiple possible types in TypeScript for JavaScript Programmers.
Recommended Free Tools
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




