Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript Tutorial
  • TS Exercise
  • TS Interview Questions
  • TS Cheat Sheet
  • TS Array
  • TS String
  • TS Object
  • TS Operators
  • TS Projects
  • TS Union Types
  • TS Function
  • TS Class
  • TS Generic
Open In App
Next Article:
How to Convert an Array of Objects into Object in TypeScript ?
Next article icon

How to Check if an Array Includes an Object in TypeScript ?

Last Updated : 24 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

In TypeScript, checking if an array includes an object consists of comparing the object's properties within the array elements. We can compare and check this using three different approaches some method, find method, and includes method.

There are several ways to check if an array includes an object in TypeScript which are as follows:

Table of Content

  • Using some method
  • Using find method
  • Using includes method

Using some method

In this approach, we are using some method with a callback function to iterate through the array and check if at least one element satisfies the condition where both the name and topic properties match those of the given object obj. The result is a boolean which represents whether the array includes the given object.

Syntax:

array.some(callback(element[, index[, array]])[, thisArg]); 

Example: The below example uses some method to check if an array includes an object in TypeScript.

JavaScript
interface inter {     name: string;     topic: string; } const arr: inter[] = [     { name: 'GFG1', topic: 'TypeScript' },     { name: 'GFG2', topic: 'JavaScript' },     { name: 'GFG3', topic: 'React' }, ]; const obj: inter = { name: 'GFG2', topic: 'JavaScript' }; const res: boolean = arr     .some(obj => obj         .name === obj             .name && obj                 .topic === obj             .topic); console.log(res);  

Output:

true 

Using find method

In this approach, we are using the find method with a callback function to search for an element in the array that satisfies the condition where both the name and topic properties match those of the specified object obj. The result, stored in temp, will either be the matching object or undefined. The boolean variable res is then set to true if a matching object is found and false if not found.

Syntax:

array.find(callback(element[, index[, array]])[, thisArg]); 

Example: The below example usthe es find method to check if an array includes an object in TypeScript.

JavaScript
interface inter {     name: string;     topic: string; } const arr: inter[] = [     {         name: 'GFG1',         topic: 'TypeScript'     },     {         name: 'GFG2',         topic: 'JavaScript'     },     {         name: 'GFG3',         topic: 'React'     }, ]; const obj: inter = {     name: 'GFG2',     topic: 'JavaScript' }; const temp: inter | undefined = arr     .find(         obj => obj             .name === obj                 .name && obj                     .topic === obj                 .topic     ); const res: boolean = !!temp; console.log(res); 

Output:

true 

Using includes method

In this approach, we are using the includes method with the map function and JSON.stringify to compare objects in the array. The map function is used to create an array of string representations of each object, and then the includes method checks if the string representation of the given object obj is present in the array.

Syntax:

array.includes(searchElement[, fromIndex]); 

Example: The below example uses includes method to check if an array includes an object in TypeScript.

JavaScript
interface inter {     name: string;     topic: string; } const arr: inter[] = [     {         name: 'GFG1',         topic: 'TypeScript'     },     {         name: 'GFG2',         topic: 'JavaScript'     },     {         name: 'GFG3',         topic: 'React'     }, ]; const obj: inter = { name: 'GFG', topic: 'JavaScript' }; const res: boolean = arr     .map(obj => JSON         .stringify(obj))     .includes(JSON.stringify(obj)); console.log(res);  

Output:

true 

Next Article
How to Convert an Array of Objects into Object in TypeScript ?

G

gauravgandal
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • TypeScript

Similar Reads

  • How to check if an array includes an object in JavaScript ?
    Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array. Since objects are compared by reference, various methods are used to identify if an object with matching properties exists in the array. These are the following appro
    3 min read
  • How to Check if an Object is Empty in TypeScript ?
    In TypeScript, it's common to encounter scenarios where you need to determine if an object is empty or not. An empty object typically means it contains no properties or all its properties are either undefined or null. Below are the methods to check if an object is empty or not in TypeScript: Table o
    3 min read
  • Check if an Array is Empty or not in TypeScript
    In TypeScript, while performing any operation on the array, it is quite important that there should be elements or data in the array, else no operation can be done. We can check whether the array contains the elements or not by using the below-listed methods: Table of Content Using length PropertyUs
    2 min read
  • How can I Define an Array of Objects in TypeScript?
    In TypeScript, the way of defining the arrays of objects is different from JavaScript. Because we need to explicitly type the array at the time of declaration that it will be an Array of objects. In this article, we will discuss the different methods for declaring an array of objects in TypeScript.
    6 min read
  • How to Convert an Array of Objects into Object in TypeScript ?
    Converting an array of objects into a single object is a common task in JavaScript and TypeScript programming, especially when you want to restructure data for easier access. In this article, we will see how to convert an array of objects into objects in TypeScript. We are given an array of objects
    3 min read
  • How to Convert a Set to an Array in TypeScript ?
    A Set in TypeScript is used to create a particular type of list that does not contain duplicate elements. If any element is repeated more than once it will automatically remove the duplicate existence and consider it only once in the list. In this article, we will convert these types of lists into a
    5 min read
  • Check if an Object is Empty in TypeScript
    In TypeScript, determining whether an object is empty involves checking if the object has any properties. This can be achieved through various built-in methods and loops. In this article, we will explore three different approaches to check if an object is empty in TypeScript. Table of Content Using
    2 min read
  • How to Check if all Enum Values Exist in an Object in TypeScript ?
    To check if all values of an enum exist in an object in TypeScript, iterate through the enum values and verify their presence in the object. This ensures that the object encompasses all possible enum values, confirming completeness and adherence to the enum definition. There are various methods to c
    3 min read
  • How to Check if a Variable is an Array in JavaScript?
    To check if a variable is an array, we can use the JavaScript isArray() method. It is a very basic method to check a variable is an array or not. Checking if a variable is an array in JavaScript is essential for accurately handling data, as arrays have unique behaviors and methods. Using JavaScript
    2 min read
  • How to Create a Typed Array from an Object with Keys in TypeScript?
    Creating a typed array from the keys of an object in TypeScript ensures that your application maintains type safety, particularly when interacting with object properties. Here we'll explore different approaches to achieve this using TypeScript's built-in Object methods. Below are the approaches used
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences