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;
    }
}
๐ŸŒ
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 returns true if the exact object reference is found in the array, making it useful when you need to confirm the presence of a specific object instance. ... Example: In this example, includes() checks if the object obj is present in the array gfg.
Published ย  July 11, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_includes_array.asp
JavaScript Array includes() Method
The includes() method returns true if an array contains a specified value.
๐ŸŒ
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.
๐ŸŒ
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:
๐ŸŒ
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?
The parameter object represents ... example code implementing above mentioned steps to check if an array includes an object in JavaScript using includes() method....
Find elsewhere
๐ŸŒ
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...
๐ŸŒ
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 ...
๐ŸŒ
Dmitri Pavlutin
dmitripavlutin.com โ€บ javascript-array-contains-value
Checking if an Array Contains a Value in JavaScript
Determining if an array contains a reference to an object is easy โ€” just use the array.includes() method.
๐ŸŒ
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 includes() method to check if the array contains JavaScript the object and an object having the passed property's value. Even though it contains the object and the object with the brand value 'HP', it ...
๐ŸŒ
JavaScript Tutorial
javascripttutorial.net โ€บ home โ€บ javascript array methods โ€บ array.prototype.includes()
JavaScript Array includes() Method
November 7, 2024 - This tutorial shows you how to use the JavaScript Array includes() method to check if an array contains a specified element.
๐ŸŒ
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.
๐ŸŒ
MDN Web Docs
devdoc.net โ€บ web โ€บ developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ includes.html
Array.prototype.includes() - JavaScript | MDN
The example below illustrates includes() method called on the function's arguments object. (function() { console.log([].includes.call(arguments, 'a')); // true console.log([].includes.call(arguments, 'd')); // false })('a','b','c'); // https://tc39.github.io/ecma262/#sec-array.prototype.includes if (!Array.prototype.includes) { Object.defineProperty(Array.prototype, 'includes', { value: function(searchElement, fromIndex) { // 1.
๐ŸŒ
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
๐ŸŒ
BackEndTea
backendtea.com โ€บ how-to โ€บ javascript-check-if-array-contains-item
Check if an array contains an element in JavaScript | BackEndTea
July 22, 2024 - With Array.includes() you can check that your array contains an exact value you are looking for.