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.
🌐
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
🌐
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:
🌐
Stack Abuse
stackabuse.com › javascript-check-if-array-contains-a-value-element
JavaScript: Check if Array Contains a Value/Element
March 8, 2023 - We've covered the includes() function, which returns a boolean value if the value is present. The indexOf() function returns the index of a value if it's present, and -1 if it isn't. Finally, for objects, the some() function helps us search for object presence based on their contents.
🌐
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
🌐
Plain English
plainenglish.io › home › blog › javascript › check if an array contains an object with a certain property value in javascript
Check if an array contains an object with a certain property value in JavaScript
December 31, 2022 - A guide to using the Array.prototype.find() method to check if an array contains an object with a certain property value in JavaScript.
Find elsewhere
🌐
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. For example: 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.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-check-if-array-contains-object
Check if Array Contains an Object in JavaScript | bobbyhadz
Use the Array.filter() method to iterate over the array. Check if each object contains a property with the specified 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?
In this approach to check if an array includes an object in JavaScript, we have used some() method. It takes a callback function and verifies whether at least one element in the array passes the test provided by the callback function. We have created an array and an object respectively, and then inserted the object in the array. Then we have used some() method to check if our array includes an object using callback function myfunction.
🌐
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 - Below are the common methods to determine if the array contains an object with an attribute. ... The Javascript array.some() method checks whether at least one of the elements of the array satisfies the condition ...
🌐
JavaScript Tutorial
javascripttutorial.net › home › how to check if an array contains a value in javascript
How to Check if an Array Contains a Value in Javascript
May 28, 2024 - To check if an array contains a primitive value, you can use the array method like array.includes() The following example uses the array.includes() method to check if the colors array contains 'red': const colors = ['red', 'green', 'blue']; ...
🌐
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 - Create an array and use includes() to determine if a specified value is present. ... const fruits = ['apple', 'banana', 'cherry']; const hasBanana = fruits.includes('banana'); console.log(hasBanana); // Output: true Explain Code · This example ...
🌐
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
This method is ideal for an array of objects. const array = [{ name: 'js' }, { name: 'css' }]; array.some(code => code.name === 'js'); // true array.some(code => code.name === '🤖'); // false · In a previous code note, I talked about a quick & dirty way to check objects using JSON.stringify().
🌐
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...
🌐
Programiz
programiz.com › javascript › examples › check-object-array
JavaScript Program to Check if An Object is An Array
In the above program, the Array.isArray() method is used to check if an object is an array. The Array.isArray() method returns true if an object is an array, otherwise returns false.
🌐
Catalin's Tech
catalins.tech › array-of-objects-contains-a-value-in-javascript
Check if an Array of Objects Contains a Value in JavaScript
October 8, 2022 - This article teaches you how to use the method Array.prototype.some() to find if an array of objects contains a value in JavaScript.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › find
Array.prototype.find() - JavaScript | MDN
If you need to find if a value exists in an array, use includes(). Again, it checks each element for equality with the value instead of using a testing function.