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
}
Answer from CAFxX on Stack Overflow
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;
    }
}
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-check-if-an-array-includes-an-object-in-javascript
How to check if an array includes an object in JavaScript ? - GeeksforGeeks
Itโ€™s ideal for complex comparisons and handling nested objects beyond shallow property checks. ... Example: In this example, _.find() from the Lodash library is used to locate an object within the array arr. If the object matches, it returns the found object. ... // Requiring the lodash library const _ = require("lodash"); // Collection of string let arr = ["geeks1", "geeks2", "geeks3", { "geeks1": 10, "geeks2": 12 }]; let obj = { "geeks1": 10, "geeks2": 12 } // Check value is found // or not by _.includes() method console.log(_.find(arr, obj));
Published ย  July 11, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-use-array-that-include-and-check-an-object-against-a-property-of-an-object
Check if an Array of Objects Includes a Specific Property Value - GeeksforGeeks
October 14, 2025 - array_name.includes(searchElement, fromIndex) To check that an Object contains a particular property or not, we have 3 methods to do this- 1. Using in operator: in operator is returns true if the property exists in the object and false if it ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ how-to-check-an-array-contains-an-object-of-attribute-with-given-value-in-javascript
How to check an Array Contains an Object of Attribute with Given Value in JavaScript ? - GeeksforGeeks
July 23, 2025 - A certain value is included in the entries of the array using Array.includes() method, it returns true if it does, false if it does not, however, this method works mostly with primitive types but for objects it may also be used by comparing ...
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array
Array - JavaScript | MDN
Array elements are object properties in the same way that toString is a property (to be specific, however, toString() is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid: ... JavaScript syntax requires ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ how-to-use-array-that-include-and-check-an-object-against-a-property-of-an-object
How to use array that include and check an object against a property of an object?
The array.some() method checks if at least one element of the array follows the particular condition passed into the callback function. So, in the callback function, we will check whether any object contains a particular property.
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ How-do-I-check-if-an-array-includes-an-object-in-JavaScript
How do I Check if an Array Includes an Object in JavaScript?
Then we have used div, getElementById method and innerHTML property to display the output. Here is a complete example code implementing above mentioned steps to check if an array includes an object in JavaScript using includes() method.
๐ŸŒ
Sentry
sentry.io โ€บ sentry answers โ€บ javascript โ€บ how do i check if an array includes a value in javascript?
How do I check if an array includes a value in JavaScript? | Sentry
There are seven primitive data types: string, number, bigint, boolean, undefined, symbol, and null. Using the includes() method is the most readable method to check if an array contains a primitive value:
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ faq โ€บ how-to-check-if-an-array-includes-an-object-in-javascript.php
How to Check If an Array Includes an Object in JavaScript
<script> // An array of objects var persons = [{name: "Harry"}, {name: "Alice"}, {name: "Peter"}]; // Find if the array contains an object by comparing the property value if(persons.some(person => person.name === "Peter")){ alert("Object found inside the array."); } else{ alert("Object not found."); } </script>
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-check-if-array-contains-object
Check if Array Contains an Object in JavaScript | bobbyhadz
We check if each element (object) in the array contains an id property with a value of 1. If the new array isn't empty, there are matching objects. Note that the Array.filter() method returns an array with all of the elements that meet the condition. If we had multiple objects with an id equal to 1, all of them would get included in the new array.
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ javascript array includes() method
JavaScript Array includes() Method - Scaler Topics
February 14, 2024 - This is how we can check if an array is an object with the passed value. We can use some() method in combination with the includes() method to check if the array contains in JavaScript atleast an element same as in another array.
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_includes_array.asp
JavaScript Array includes() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
๐ŸŒ
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
๐ŸŒ
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...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ array contains in javascript
Array Contains in JavaScript - Scaler Topics
January 16, 2024 - In the above-given example, we used the filter() method with an arrow function to check if the array contains JavaScript the object. There's a callback function in the filter() method to check if the element is present in the array or not. We know that the filter() method creates a new array containing the elements that satisfy the given condition, hence if there's an element(or object) that satisfies the given condition, it gets added to the new array in such cases the array length must be greater than zero. Hence we are using the length property of the array to validate if the array length is positive(>0) or not, if its positive we update the value of isPresent from false to true.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ javascript-check-if-array-contains-a-value-element
JavaScript: Check if Array Contains a Value/Element
March 8, 2023 - When searching for an object, includes() checks whether the provided object reference matches the one in the array.
๐ŸŒ
Intellipaat
intellipaat.com โ€บ home โ€บ blog โ€บ how to check if an array includes an object in javascript?
How to Check if an Array Includes an Object in JavaScript? (With Examples)
October 29, 2025 - Well, JavaScript provides you with ... us discuss all of them one by one: The includes() method is used to check objects in an array in JavaScript for both primitive and reference data types....