When I build a sales dashboard or process customer records from an API, I often need to confirm whether an array already contains a value before taking the next step. For example, you may want to check whether a sales region exists, whether a product ID is already selected, or whether a support ticket has a specific status.
TypeScript makes these checks safer because it adds static type checking to JavaScript. You still use familiar JavaScript array methods, but TypeScript helps ensure that you check the right kind of value.
In this tutorial, you will learn the best ways to check if a TypeScript array contains a specific value, including strings, numbers, objects, readonly arrays, and reusable generic functions.
Check if a TypeScript Array Contains a Specific Value
The simplest way to check whether an array contains a specific primitive value is the includes() method. A primitive value is a basic value such as a string, number, or boolean. The includes() method returns true when it finds an exact match. Otherwise, it returns false.
This works well in Node.js TypeScript scripts, browser applications, automation tools, and backend services.
Use includes() with a string array
Suppose you are building a small sales-reporting script. You receive a list of sales regions and need to confirm whether the "West" region exists before generating a report.
const salesRegions: string[] = ["East", "West", "North", "South"];
const selectedRegion = "West";
const regionExists = salesRegions.includes(selectedRegion);
console.log(`Does ${selectedRegion} exist?`, regionExists);
Sample output:
Does West exist? true
You can refer to the screenshot below to see the output.

The salesRegions variable uses the string[] type, which means the array can only contain strings. The includes() method checks each value and stops as soon as it finds "West".
This method does not change the original array. It only reads the array and returns a boolean value.
If you are new to array types, also read how to initialize an array in TypeScript and work with const arrays in TypeScript.
Check for a number in an array
You can use the same approach with a number[] array. This is useful when checking order IDs, invoice numbers, item quantities, or selected record IDs.
const completedOrderIds: number[] = [1024, 1028, 1035, 1041];
const orderIdToCheck = 1035;
const orderExists = completedOrderIds.includes(orderIdToCheck);
console.log(`Order ${orderIdToCheck} completed:`, orderExists);
Sample output:
Order 1035 completed: true
Here, TypeScript knows that completedOrderIds contains numbers. If you accidentally try to search for "1035" as a string, TypeScript can flag the mismatch before you run the code.
const completedOrderIds: number[] = [1024, 1028, 1035, 1041];
const orderIdToCheck = "1035";
// This line causes a TypeScript error because the array holds numbers.
// const orderExists = completedOrderIds.includes(orderIdToCheck);
console.log("Use a number value when checking a number array.");
Sample output:
Use a number value when checking a number array.
You can refer to the screenshot below to see the output.

This is a useful example of type safety. Type safety means TypeScript checks whether your values match the expected types before JavaScript runs.
Use includes() for TypeScript Array Checks
For most string, number, and boolean arrays, includes() is the cleanest option. It clearly communicates your intent: you want to know whether a value exists.
Check multiple allowed values
A common requirement involves checking whether an array contains any value from another array. For example, a sales application may allow only users with "manager" or "admin" roles to export customer data.
const userRoles: string[] = ["sales-rep", "report-viewer"];
const exportRoles: string[] = ["manager", "admin"];
const canExportReports = exportRoles.some((role) => userRoles.includes(role));
console.log("Can export reports:", canExportReports);
Sample output:
Can export reports: false
This code combines two useful TypeScript array methods:
includes()checks whetheruserRolescontains one role.some()checks whether at least one role fromexportRolesmatches.
The some() method returns true immediately when it finds a match. It does not modify either array.
Now update the user roles to include "manager".
const userRoles: string[] = ["sales-rep", "manager"];
const exportRoles: string[] = ["manager", "admin"];
const canExportReports = exportRoles.some((role) => userRoles.includes(role));
console.log("Can export reports:", canExportReports);
Sample output:
Can export reports: true
You can refer to the screenshot below to see the output.

For more practical looping patterns, see for-of loops in TypeScript and TypeScript for loops with arrays.
Pro Tip: I use
includes()for simple values andsome()for object arrays. I avoid manual loops unless I need extra validation, logging, or early business-rule checks inside the loop.
Check an Array of Objects in TypeScript
The includes() method works perfectly for primitive values. However, it often produces surprising results with objects.
An object stores data through properties. For example, a customer record might include an ID, name, region, and account status. In TypeScript, an interface defines the expected structure of that object.
Why includes() does not reliably find matching objects
Consider a list of customers in a sales application.
interface Customer {
id: number;
name: string;
region: string;
}
const customers: Customer[] = [
{ id: 101, name: "Emily Carter", region: "West" },
{ id: 102, name: "Michael Johnson", region: "East" },
{ id: 103, name: "Olivia Brown", region: "South" }
];
const customerToFind: Customer = {
id: 102,
name: "Michael Johnson",
region: "East"
};
const customerExists = customers.includes(customerToFind);
console.log("Customer exists:", customerExists);Sample output:
Customer exists: false
The output is false even though the object has the same property values as Michael Johnson’s record.
That happens because includes() compares object references, not the individual property values. The object inside customers and customerToFind are two different objects in memory.
To learn more about typed records, see arrays of objects in TypeScript and creating an object from an interface in TypeScript.
Use some() to check an object property
For object arrays, use some() with a property that uniquely identifies the record. In most applications, that property is an ID.
interface Customer {
id: number;
name: string;
region: string;
}
const customers: Customer[] = [
{ id: 101, name: "Emily Carter", region: "West" },
{ id: 102, name: "Michael Johnson", region: "East" },
{ id: 103, name: "Olivia Brown", region: "South" }
];
const customerIdToFind = 102;
const customerExists = customers.some(
(customer) => customer.id === customerIdToFind
);
console.log(`Customer ID ${customerIdToFind} exists:`, customerExists);Sample output:
Customer ID 102 exists: true
The callback function receives one customer at a time. It compares the customer’s id with the ID you want to find. The method returns true at the first match.
This approach does not mutate the original customers array. It simply checks its records.
If you need the object itself instead of a boolean result, use find().
interface Customer {
id: number;
name: string;
region: string;
}
const customers: Customer[] = [
{ id: 101, name: "Emily Carter", region: "West" },
{ id: 102, name: "Michael Johnson", region: "East" },
{ id: 103, name: "Olivia Brown", region: "South" }
];
const customerIdToFind = 103;
const customer = customers.find(
(customer) => customer.id === customerIdToFind
);
console.log("Matching customer:", customer);Sample output:
Matching customer: { id: 103, name: 'Olivia Brown', region: 'South' }The find() method returns the first matching object or undefined if no match exists. Check for undefined before using its properties.
interface Customer {
id: number;
name: string;
region: string;
}
const customers: Customer[] = [
{ id: 101, name: "Emily Carter", region: "West" },
{ id: 102, name: "Michael Johnson", region: "East" }
];
const customerIdToFind = 999;
const customer = customers.find(
(customer) => customer.id === customerIdToFind
);
if (customer) {
console.log(`Customer found: ${customer.name}`);
} else {
console.log(`No customer found for ID ${customerIdToFind}`);
}Sample output:
No customer found for ID 999
This pattern protects your application from trying to read customer.name when no customer exists. It is especially helpful when working with API responses. You can also learn how to find an object in a TypeScript array and search an array of objects by property in TypeScript.
Check Values with indexOf() in TypeScript
The indexOf() method is another way to check whether an array contains a value. It returns the index position of the first matching item. If no match exists, it returns -1.
Use indexOf() when you need both the existence check and the value’s position.
const dashboardWidgets: string[] = [
"Sales Summary",
"Regional Performance",
"Top Products",
"Monthly Revenue"
];
const widgetToFind = "Top Products";
const widgetIndex = dashboardWidgets.indexOf(widgetToFind);
console.log("Widget index:", widgetIndex);
console.log("Widget exists:", widgetIndex !== -1);
Sample output:
Widget index: 2
Widget exists: true
Array indexes start at 0, so "Top Products" appears at index 2.
The method does not change the original array. However, if you only need true or false, includes() is easier to read.
const dashboardWidgets: string[] = [
"Sales Summary",
"Regional Performance",
"Top Products"
];
const widgetToFind = "Customer Retention";
if (dashboardWidgets.indexOf(widgetToFind) === -1) {
console.log(`${widgetToFind} is not available.`);
}
Sample output:
Customer Retention is not available.
Avoid using if (dashboardWidgets.indexOf(widgetToFind)). A matching item at index 0 evaluates as false in JavaScript. Always compare the result with -1.
Create a Reusable Generic Function
A generic function is a reusable function that works with many data types while preserving TypeScript’s type safety. It is useful when your project checks values across several typed arrays.
The <T> in the example below represents a type placeholder. TypeScript replaces T with the appropriate type when you call the function.
function containsValue<T>(items: readonly T[], value: T): boolean {
return items.includes(value);
}
const salesRegions: string[] = ["East", "West", "North"];
const priorityLevels: number[] = [1, 2, 3];
const hasWestRegion = containsValue(salesRegions, "West");
const hasPriorityThree = containsValue(priorityLevels, 3);
console.log("Contains West:", hasWestRegion);
console.log("Contains priority 3:", hasPriorityThree);Sample output:
Contains West: true
Contains priority 3: true
The readonly T[] parameter accepts both normal arrays and a readonly array. A readonly array is an array that TypeScript prevents you from modifying.
This function does not change the source array. It calls includes(), which only checks for a value.
You can use the same function with a readonly list of permitted sales regions.
function containsValue<T>(items: readonly T[], value: T): boolean {
return items.includes(value);
}
const allowedRegions: readonly string[] = ["East", "West", "North"];
const requestedRegion = "South";
const regionIsAllowed = containsValue(allowedRegions, requestedRegion);
console.log(`${requestedRegion} is allowed:`, regionIsAllowed);Sample output:
South is allowed: false
TypeScript will not allow allowedRegions.push("South") because the array is readonly. That restriction protects configuration-style data from accidental changes. You can explore this pattern further in this guide to readonly arrays in TypeScript.
Check Case-Insensitive String Values
By default, includes() treats uppercase and lowercase letters as different characters. "west" and "West" do not match.
In user-facing applications, normalize both values before you compare them. Normalizing means converting data into one consistent format.
const salesRegions: string[] = ["East", "West", "North"];
const userInput = "west";
const normalizedInput = userInput.trim().toLowerCase();
const regionExists = salesRegions.some(
(region) => region.toLowerCase() === normalizedInput
);
console.log(`Region "${userInput}" exists:`, regionExists);
Sample output:
Region "west" exists: true
The trim() method removes extra spaces before and after the input. Then toLowerCase() makes the comparison consistent.
This solution does not modify salesRegions. The callback creates lowercase strings only for comparison. If you process many thousands of values repeatedly, normalize and store the values once instead of converting each value every time.
For related string handling, read how to convert a string to lowercase in TypeScript and check if a string contains a substring in TypeScript.
Things to Keep in Mind
- Use includes() for primitive values: It gives the clearest boolean check for string, number, and boolean arrays.
- Use some() for object arrays:
includes()compares object references, whilesome()lets you compare an ID or another property. - Check indexOf() against -1: Do not use an index directly in an
ifstatement because index0is a valid match. - Preserve type safety: Keep array and search values in the same type, such as
number[]with a number search value. - Avoid unnecessary normalization: Converting every string repeatedly can add work when processing large datasets.
- Support readonly arrays: Use
readonly T[]in generic functions when the function only reads data.
Frequently Asked Questions
How do I check if a TypeScript array contains a value?
Use the includes() method for strings, numbers, or booleans. For example, colors.includes("Blue") returns true when "Blue" exists in the array. This method does not change the array.
Does includes() work with an array of objects in TypeScript?
It works only when you pass the exact same object reference stored in the array. It does not compare object properties such as id or name. Use some() when you need to find an object by a property value.
What is the best way to check if an object exists in a TypeScript array?
Use some() with a unique property such as an ID. For example, customers.some(customer => customer.id === 102) returns a boolean. Use find() instead if you need the matching object after the check.
Does includes() change the original TypeScript array?
No. The includes() method only reads the array and returns true or false. It does not add, remove, sort, reverse, or otherwise mutate array values.
Should I use includes() or indexOf() in TypeScript?
Use includes() when you only need a boolean result. Use indexOf() when you also need the position of the matching value. For new code, I usually choose includes() because it reads more naturally.
How do I check a TypeScript readonly array for a value?
You can call includes() on a readonly array because it only reads data. You can also write a generic function that accepts readonly T[]. TypeScript blocks methods such as push() and pop() on readonly arrays.
You May Also Like
- Check if an array is empty in TypeScript
- Get distinct values from an array in TypeScript
- Filter arrays in TypeScript
- Remove an item from an array in TypeScript
- Sort arrays in TypeScript
Checking whether a TypeScript array contains a specific value is straightforward once you choose the right method. Use includes() for primitive values, some() for matching object properties, and indexOf() when you also need the item position.
For most projects, start with includes() and let TypeScript’s type safety prevent mismatched values before they reach production. I hope you found this article helpful.

Bijay Kumar is an experienced Python and AI professional who enjoys helping developers learn modern technologies through practical tutorials and examples. His expertise includes Python development, Machine Learning, Artificial Intelligence, automation, and data analysis using libraries like Pandas, NumPy, TensorFlow, Matplotlib, SciPy, and Scikit-Learn. At PythonGuides.com, he shares in-depth guides designed for both beginners and experienced developers. More about us.