There is no contains method but you can use some()

Here is an example:

const exists = this.state.credentialsList.some(v => (v.user === credential.user && v.password === credential.password));

The code above checks if any of the objects inside the credentialsList array has the same user and password properties values as the credential object. You can modify the if condition if you don't want to check for both these properties.

Answer from Titus on Stack Overflow
🌐
Bobby Hadz
bobbyhadz.com › blog › react-check-if-element-exists-in-array
Check if an Element exists in an Array in React | bobbyhadz
Use the Array.includes() method to check if a primitive value exists in an array. The includes() method will return true if the value exists in an array and false otherwise. App.js · Copied!import {useState} from 'react'; const App = () => ...
🌐
React
legacy.reactjs.org › docs › introducing-jsx.html
Introducing JSX – React
It also allows React to show more useful error and warning messages. With that out of the way, let’s get started! In the example below, we declare a variable called name and then use it inside JSX by wrapping it in curly braces: const name = 'Josh Perez';const element = <h1>Hello, {name}</h1>; You can put any valid JavaScript expression inside the curly braces in JSX.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.
🌐
Stack Overflow
stackoverflow.com › questions › 72889931 › using-includes-in-react-with-arrays
javascript - using includes in React with arrays - Stack Overflow
console.log(data1): Test Array(2) 0: {Name: 'TEST', item: 'Crayons'} 1: {Name: 'TEST', item: 'Taco'} console.log(data2) : {Name: 'Jack', place: 'Home', item: 'Taco'} console.log(data2.item) : Taco console.log([data1].includes(data2.item)) : False
🌐
W3Schools
w3schools.com › jsref › jsref_includes_array.asp
JavaScript Array includes() Method
The includes() method is case sensitive. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make a suggestion, send us an e-mail: help@w3schools.com · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
Telerik
telerik.com › blogs › react-basics-working-react-objects
React Basics: Working with React Objects
October 10, 2023 - React objects are an integral part of React, which is a popular JavaScript library for building user interfaces. Essentially, they are JavaScript objects that represent a component in a React application.
🌐
Quora
quora.com › How-do-I-check-if-an-array-includes-an-object-in-JavaScript
How to check if an array includes an object in JavaScript - Quora
Answer (1 of 6): There are two ways to do this, using a [code ]for[/code] loop or using ES6’s [code ]Array.prototype.includes()[/code] method. At the end, I will show you some other helpers if you have arrays that contain objects. Using [code ]Array.prototype.includes()[/code] Syntax: [code]my...
Top answer
1 of 16
2277

There isn't any need to reinvent the wheel loop, at least not explicitly.

Use some as it allows the browser to stop as soon as one element is found that matches:

if (vendors.some(e => e.Name === 'Magenic')) {
  // We found at least one object that we're looking for!
}

or the equivalent (in this case) with find, which returns the found object instead of a boolean:

if (vendors.find(e => e.Name === 'Magenic')) {
  // Usually the same result as above, but find returns the element itself
}

If you'd like to get the position of that element, use findIndex:

const i = vendors.findIndex(e => e.Name === 'Magenic');
if (i > -1) {
  // We know that at least 1 object that matches has been found at the index i
}

If you need to get all of the objects that match:

if (vendors.filter(e => e.Name === 'Magenic').length > 0) {
  // The same result as above, but filter returns all objects that match
}

If you need compatibility with really old browsers that don't support arrow functions, then your best bet is:

if (vendors.filter(function(e) { return e.Name === 'Magenic'; }).length > 0) {
  // The same result as above, but filter returns all objects that match and we avoid an arrow function for compatibility
}
2 of 16
388

2018 edit: This answer is from 2011, before browsers had widely supported array filtering methods and arrow functions. Have a look at CAFxX's answer.

There is no "magic" way to check for something in an array without a loop. Even if you use some function, the function itself will use a loop. What you can do is break out of the loop as soon as you find what you're looking for to minimize computational time.

var found = false;
for(var i = 0; i < vendors.length; i++) {
    if (vendors[i].Name == 'Magenic') {
        found = true;
        break;
    }
}
Find elsewhere
🌐
DEV Community
dev.to › onlinemsr › javascript-includes-method-the-top-10-things-you-need-to-know-17jc
JavaScript Includes() Method: The Top 10 Things You Need to Know - DEV Community
July 8, 2023 - By understanding its various use cases and avoiding common mistakes, you can use includes() to write more efficient and effective JavaScript code. So go ahead and give it a try in your own projects! Content re-published from www.rajamsr.com. ... Hi, I'm Raja, a software engineer with a passion for learning new things. I have experience in developing web applications using .NET, JavaScript, React, Angular, and DevOps
🌐
TheServerSide
theserverside.com › tutorial › JavaScript-React-and-object-oriented-programming
JavaScript, React and object-oriented programming | TheServerSide
The following code shows an example of a React component programmed in JavaScript. The component calculates a random number and emits the result within a <div> element when the page loads. Notice that the code contains both the logic to create a random number and the HTML markup that includes that random number.
🌐
Mimo
mimo.org › glossary › javascript › includes-method
JavaScript includes() method: Syntax, Usage, and Examples
JavaScript includes () is often used for validation, filtering, and quick membership checks without having to loop through data manually. The method is clean, concise, and extremely useful in both array and string contexts. ... Become a full-stack developer. Learn HTML, CSS, JavaScript, and ...
🌐
React
react.dev › learn › updating-objects-in-state
Updating Objects in State – React
State can hold any kind of JavaScript value, including objects. But you shouldn’t change objects that you hold in the React state directly.
🌐
GeeksforGeeks
geeksforgeeks.org › reactjs › jsxelement-vs-reactelement-vs-reactnode
JSX.Element vs ReactElement vs ReactNode - GeeksforGeeks
July 23, 2025 - It is an immutable JavaScript object containing all the necessary information to create and manage the DOM nodes or other outputs in a React application. It is characterized by its immutability, meaning it cannot be changed once created.
🌐
SheCodes
shecodes.io › athena › 220596-how-to-use-the-includes-method-in-javascript
[JavaScript] - How to use the .includes() method in | SheCodes
Learn how to use the `.includes()` method in JavaScript to check if a specific string or element is present in another string or array.
🌐
SamanthaMing
samanthaming.com › tidbits › 81-how-to-check-if-array-includes-a-value
How to check if array includes a value in JavaScript? | SamanthaMing.com
In a previous code note, I talked about a quick & dirty way to check objects using JSON.stringify(). ... const array = [{ name: 'js' }, { name: 'css' }]; array.some(code => JSON.stringify(code) === JSON.stringify({ name: 'css' })); // true ... const array = ['SAMANTHA']; array.includes('samantha'); // false array.indexOf('samantha') !== -1; // false
🌐
Medium
d7k.medium.com › js-includes-vs-some-b3cd546a7bc3
JS .includes() vs .some(). JavaScript array is a powerful data… | by Ashan Dhananjaya | Medium
November 20, 2019 - Internally, it .includes() makes a comparison through ===. However, comparisons with ===or==only work as expected (compare value) with the types: ... When we compare variables that reference the type object, the interpreter will test whether they point to the same object in memory.
🌐
GeeksforGeeks
geeksforgeeks.org › how-to-check-if-an-array-includes-an-object-in-javascript
How to check if an array includes an object in JavaScript ? | GeeksforGeeks
Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array.
Published   September 5, 2024
🌐
freeCodeCamp
forum.freecodecamp.org › t › react-how-to-access-object-within-object › 360319
React - How to access Object within Object? - The freeCodeCamp Forum
March 18, 2020 - I have the current JSON object, named ‘data’. It has the following form: { "1": { "A" { "a": 2 } } } I’m not sure of how I’m supposed to access the 2. I’ve tried everything. The errors keep coming back as undefined. All I need to do is access whatever value is attached to "a". I’ve ...
🌐
React
legacy.reactjs.org › docs › lists-and-keys.html
Lists and Keys – React
In React, transforming arrays into lists of elements is nearly identical. You can build collections of elements and include them in JSX using curly braces {}. Below, we loop through the numbers array using the JavaScript map() function. We return a <li> element for each item.