What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use Array.find() to get the first object that matches a condition. Because no match produces undefined, check the result before reading its properties.
Find an object by a property
For example, to find the user whose id is 2:
type User = {
id: number;
name: string;
};
const users: User[] = [
{ id: 1, name: "Ada" },
{ id: 2, name: "Grace" },
];
const targetId = 2;
const user = users.find((candidate) => candidate.id === targetId);
if (user !== undefined) {
console.log(user.name);
} else {
console.log("No user found");
}
The callback receives each array element; its condition compares the object’s id with the target. find is the appropriate choice when you want one matching element. TypeScript’s Everyday Types handbook shows this kind of lookup and notes that the result may be undefined if nothing matches.
Handle the missing result
With strictNullChecks enabled, TypeScript flags attempts to access a property on a result that might be undefined. Narrow the result first with a check such as user !== undefined, as in the example. This makes the no-match case explicit and lets TypeScript know the object exists inside that branch.
This handles a missing match, not a missing array. The example assumes users is an array; if the variable holding the array can itself be nullish, handle that input separately before calling find.
#1 Best Overall
Use a different method when you need a collection
If the goal is every matching object rather than one, use filter, which returns a collection of matches. For union-typed arrays, the TypeScript narrowing handbook demonstrates passing a user-defined type guard to filter so the resulting array is narrowed to the guarded member type.
If TypeScript does not recognize find
The TSConfig lib reference lists array.find among the APIs available through the ES2015 library definitions. If the compiler reports that find is unavailable, inspect the project’s lib configuration and runtime environment. A library declaration tells the type checker about an API; it does not add a polyfill to a runtime that lacks the method.
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
TypeScript 5.2 also documents typing changes for methods such as filter and find on certain unions of arrays: results can be an array of the union element type instead of preserving the original union-of-arrays shape. This is a version-specific note for union-array typing, not a special setup requirement for an ordinary User[] lookup. See the TypeScript 5.2 release notes.
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.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →




