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
๐ŸŒ
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.
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;
    }
}
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_includes_array.asp
JavaScript Array includes() Method
โฎ Previous JavaScript Array Reference ... fruits.includes("Banana", 3); Try it Yourself ยป ยท The includes() method returns true if an array contains a specified value....
๐ŸŒ
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
These are the following approaches by using these we can check if an array includes an object in JavaScript: ... The includes() method checks if an array contains a specific object by reference.
Published ย  July 11, 2025
๐ŸŒ
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 ...
๐ŸŒ
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 ...
๐ŸŒ
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:
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ javascript โ€บ includes-method
JavaScript includes() method: Syntax, Usage, and Examples
Learn HTML, CSS, JavaScript, and ... functions, objects, and modern ES6+ features ... The includes() method determines whether a string or an array contains a specified value, returning true or false as appropriate....
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?
In this approach to check if an array includes an object in JavaScript, we have used Lodash _.find() method. We have created an array and an object respectively, and then inserted the object in the 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
๐ŸŒ
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...
๐ŸŒ
Built In
builtin.com โ€บ software-engineering-perspectives โ€บ javascript-array-contains
JavaScript Array Contains: 6 Methods to Find a Value | Built In
Summary: JavaScript offers multiple methods to check if an array contains a value, including indexOf, includes, some, find and findIndex. While indexOf fails with NaN, includes detects it. Object searches use callback functions with some, find ...
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ check-if-an-item-is-in-an-array-in-javascript-js-contains-with-array-includes
Check if an Item is in an Array in JavaScript โ€“ JS Contains with Array.includes()
June 28, 2022 - You can use the includes() method in JavaScript to check if an item exists in an array. You can also use it to check if a substring exists within a string. It returns true if the item is found in the array/string and false if the item doesn't ...
๐ŸŒ
BackEndTea
backendtea.com โ€บ how-to โ€บ javascript-check-if-array-contains-item
Check if an array contains an element in JavaScript | BackEndTea
July 22, 2024 - const trees = ['oak', 'willow', 'maple', 'yew', 'magic']; console.log(trees.includes('oak')); // true console.log(trees.includes('normal')); // false ยท However, if your array contains objects, Array.includes() may not work as expected because it checks for the same object reference, not just the content.
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript array methods โ€บ array.prototype.includes()
JavaScript Array includes() Method
November 7, 2024 - Summary: In this tutorial, you will learn how to use the JavaScript Array includes() method to check if an array includes an element. The Array includes() method returns true if an array contains an element or false otherwise.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ javascript โ€บ examples โ€บ check-if-an-array-contains-a-specified-value
JavaScript Program to Check if An Array Contains a Specified Value | Vultr Docs
September 27, 2024 - This example demonstrates checking for 'banana' in the fruits array. The includes() method returns true since 'banana' is indeed 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 - Yes, a JavaScript array contain objects as its elements. Q7. Why does array.includes(obj) return false for identical objects?