Check if a TypeScript Array Contains a Specific Value
To check if a TypeScript array contains a specific value, call includes(): cities.includes(“Denver”) returns true or false. That works for strings, numbers and booleans. For an array of objects it will not, because includes() compares by reference, so you test a property with some() instead: orders.some(o => o.id === “ORD-1001”). This guide covers both, plus … Read more >>