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
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Includes vs. In - JavaScript - The freeCodeCamp Forum
August 18, 2022 - Today I ran into some trouble with a line of code that seems to be misleading. I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having difficulty understanding the difference between the array.includes() function and ...
🌐
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.
🌐
GitHub
github.com › zloirock › core-js
GitHub - zloirock/core-js: Standard Library
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2025: promises, symbols, collections, iterators, typed arrays, many other features, ECMAScript proposals, some cross-platform WHATWG / W3C features and proposals ...
Starred by 25.5K users
Forked by 1.7K users
Languages   JavaScript
🌐
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;
    }
}
🌐
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 ...
Find elsewhere
🌐
Tabnine
tabnine.com › home › how to use the includes() method in javascript
How to Use the includes() Method in JavaScript - Tabnine
July 25, 2024 - The includes() method is part of both the Array and String prototypes. This method accepts a search value as a parameter, and returns true if the value is either contained in the array on which it is called, or if it exists as a substring of ...
🌐
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
Check if an array includes an object in JavaScript, which refers to determining whether a specific object is present within an array.
Published   July 11, 2025
🌐
Mozilla
developer.mozilla.org › en-US › docs › Web › JavaScript › Guide › Working_with_objects
Working with objects - JavaScript | MDN
1 week ago - An object can have a property that is itself another object. For example, suppose you define an object called Person as follows: ... Then, you can rewrite the definition of Car to include an owner property that takes a Person object, as follows:
🌐
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 ...
🌐
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
🌐
ESLint
eslint.org › docs › latest › use › configure › configuration-files
Configuration Files - ESLint - Pluggable JavaScript Linter
This configuration object applies to all JavaScript files except those ending with .config.js. Effectively, this is like having files set to **/*. In general, it’s a good idea to always include files if you are specifying ignores.
🌐
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
A primitive value is a value that’s not an object. 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:
🌐
W3Schools
w3schools.com › js › js_array_search.asp
JavaScript Array Search
Object Study Path Object Intro Object Properties Object Methods Object this Object Display Object Constructors JS Scope
🌐
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....