Assuming you want to find the substring in the property value, you can use the following code:

const arr = [
  {a:'abc', b:'efg', c:'hij'},
  {a:'abc', b:'efg', c:'hij'},
  {a:'123', b:'456', c:'789'},
];

const search = 'a';

const res = arr.filter(obj => Object.values(obj).some(val => val.includes(search)));

console.log(res);

If you want to search the property name, use Object.keys instead of Object.values.

Please note that Object.values is a feature of ES2017.

Answer from str on Stack Overflow
🌐
Brainstorm Creative
brainstormcreative.co.uk › home › javascript › how to search for a string or object in an array in javascript
How to search for a string or object in an array in Javascript
April 21, 2023 - For years the way to search in an array of objects would be to use a for loop to iterate through each item, compare the strings, and then do something when you found a match in the array.
🌐
W3Schools
w3schools.com › js › js_array_search.asp
JavaScript Array Search
JS Examples JS HTML DOM JS HTML ... Prep JS Bootcamp JS Certificate JS Reference ... The indexOf() method searches an array for an element value and returns its position....
🌐
DigitalOcean
digitalocean.com › community › tutorials › js-array-search-methods
Four Methods to Search Through Arrays in JavaScript | DigitalOcean
December 15, 2021 - Learn about four approaches to searching for values in arrays: includes, indexOf, find, and filter methods.
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › find
Array.prototype.find() - JavaScript - MDN Web Docs
July 20, 2025 - It calls a provided callbackFn function once for each element in an array in ascending-index order, until callbackFn returns a truthy value. find() then returns that element and stops iterating through the array. If callbackFn never returns a truthy value, find() returns undefined.
🌐
Stack Overflow
stackoverflow.com › questions › 16191183 › want-to-search-string-in-the-array-of-objects › 16191314
javascript - Want to search string in the array of objects? - Stack Overflow
April 24, 2013 - If you don’t know the structure, ... it won’t be as safe): function search_for_string_in_array(str, arr) { var json = JSON.stringify(arr); return new RegExp(':\"'+str+'\"','g').test(json); }...
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript find object in array
How to Search Objects From an Array in JavaScript | Delft Stack
February 2, 2024 - The find() method is an alternate way of finding objects and their elements from an array in JavaScript. The find() is an ES6 method.
🌐
UsefulAngle
usefulangle.com › post › 3 › javascript-search-array-of-objects
How to Search in an Array of Objects with Javascript
April 4, 2020 - Searching in an array of objects can be done in Javascript using a loop, Array.find() or Array.findIndex() methods.
Top answer
1 of 16
2212

Use the find() method:

myArray.find(x => x.id === '45').foo;

From MDN:

The find() method returns the first value in the array, if an element in the array satisfies the provided testing function. Otherwise undefined is returned.


If you want to find its index instead, use findIndex():

myArray.findIndex(x => x.id === '45');

From MDN:

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise -1 is returned.


If you want to get an array of matching elements, use the filter() method instead:

myArray.filter(x => x.id === '45');

This will return an array of objects. If you want to get an array of foo properties, you can do this with the map() method:

myArray.filter(x => x.id === '45').map(x => x.foo);

Side note: methods like find() or filter(), and arrow functions are not supported by older browsers (like IE), so if you want to support these browsers, you should transpile your code using Babel (with the polyfill).

2 of 16
1502

As you are already using jQuery, you can use the grep function which is intended for searching an array:

var result = $.grep(myArray, function(e){ return e.id == id; });

The result is an array with the items found. If you know that the object is always there and that it only occurs once, you can just use result[0].foo to get the value. Otherwise you should check the length of the resulting array. Example:

if (result.length === 0) {
  // no result found
} else if (result.length === 1) {
  // property found, access the foo property using result[0].foo
} else {
  // multiple items found
}
🌐
Ubiq BI
ubiq.co › home › how to search for object in array of objects in javascript
How to Search For Object in Array of Objects in JavaScript - Ubiq BI
March 6, 2025 - First, we learnt how to find single occurrence of an item in array of objects using find() function. Then we learnt how to get an array of matching items, using filter() function, in case there are multiple occurrences of matching objects.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-find-an-object-by-property-value-in-an-array-of-javascript-objects.php
How to Find an Object by Property Value in an Array of JavaScript Objects
PHP Array Functions PHP String Functions PHP File System Functions PHP Date/Time Functions PHP Calendar Functions PHP MySQLi Functions PHP Filters PHP Error Levels ... You can simply use the find() method to find an object by a property value ...
🌐
Mimo
mimo.org › glossary › javascript › array-find
JavaScript Array() Find: Syntax, Usage, and Examples
You can easily search for strings that meet specific conditions using the array find JavaScript method. A common use case for find() is searching for objects in arrays of objects.
Top answer
1 of 2
1

Thanks for providing some example code. That helps.

Let's start with your function, which has a good signature:

const excludeItems = (arrayOfSearchItems, arrayOfObjects) => { ... }

If we describe what this function should do, we would say "it returns a new array of objects which do not contain any of the search items." This gives us a clue about how we should write our code.

Since we will be returning a filtered array of objects, we can start by using the filter method:

return arrayOfObjects.filter(obj => ...)

For each object, we want to make sure that its storage does not contain any of the search items. Another way to word this is "every item in the starage array does NOT appear in the list of search items". Now let's write that code using the every method:

.filter(obj => {
  // ensure "every" storage item matches a condition
  return obj.storage.every(storageItem => {
    // the "condition" is that it is NOT in the array search items
    return arrayOfSearchItems.includes(storageItem) === false);
  });
});

Putting it all together:

const excludeItems = (arrayOfSearchItems, arrayOfObjects) => {
    return arrayOfObjects.filter(obj => {
        return obj.storage.every(storageItem => {
            return arrayOfSearchItems.includes(storageItem) === false;
        });
    });
}

Here's a fiddle: https://jsfiddle.net/3p95xzwe/

2 of 2
0

You can achieve your goal by using some of the built-in Array prototype functions, like filter, some and includes.

const excludeItems = (search, objs) => 
  objs.filter(({storage:o}) => !search.some(s => o.includes(s)));

In other words: Filter my array objs, on the property storage to keep only those that they dont include any of the strings in search.

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-search-character-in-list-of-array-object-inside-an-array-object-in-javascript
How to Search Character in List of Array Object Inside an Array Object in JavaScript ? - GeeksforGeeks
July 23, 2025 - Searching for a character in a list of array objects inside an array object involves inspecting each array object, and then examining each array within for the presence of the specified character.