Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and work.

aviboots(AT)netvision.net.il

Instant Grammar Checker - Correct all grammar errors and enhance your writing
BlueHost Web Hosting

Profollica™ is a standout product in the hair regrowth industry.

New Arrival!  Shop NOW for metal eyeglasses at GlassesShop.com!

Bonsai Boy of New York Bonsai Trees and Accessories

DreamCloud The Comfortable Luxury Mattress Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

DreamHost Web Hosting


Liquid Web Cloud VPS Hosting

Disclosure We are a professional Programming & Software Q&A website, that receives compensation from some of the links whose we show you with Information. It means that my content may contain affiliate links.

13,568 questions

18,473 answers

573 users

How to search in an array of objects with Javascript

4 Answers

0 votes
function searchArrayofObjects(workers, s) {
    for (let i = 0; i < workers.length; i++) {
        if (workers[i].name === s) {
            return true
        }
    }
    return false;
}
 
var workers = [
    { id: 13451, name: 'Axel'},
    { id: 87134, name: 'Blaze'},
    { id: 79372, name: 'Dexter'},
    { id: 39810, name: 'Isla'}
];
   
console.log(searchArrayofObjects(workers, 'Isla'));
 
 
   
   
/*
run:
       
true
    
*/

 




answered Jun 17 by avibootz
edited Jun 17 by avibootz
0 votes
var workers = [
    { id: 13451, name: 'Axel'},
    { id: 87134, name: 'Blaze'},
    { id: 79372, name: 'Alma'},
    { id: 39810, name: 'Isla'}
];
  
  
var __SEARCH = workers.find(function(workers, index) {
	if (workers.name === 'Alma')
		return true;
});  
  
console.log(__SEARCH);


  
  
/*
run:
      
{ id: 79372, name: 'Alma' }

*/

 




answered Jun 17 by avibootz
0 votes
var workers = [
    { id: 13451, name: 'Axel'},
    { id: 87134, name: 'Blaze'},
    { id: 79372, name: 'Alma'},
    { id: 39810, name: 'Isla'}
];
   

s = 'Alma';
   
var __SEARCH = workers.find(function(workers, index) {
    if (workers.name === s)
        return true;
});  
   
console.log(__SEARCH);
 
 
   
   
/*
run:
       
{ id: 79372, name: 'Alma' }
 
*/

 




answered Jun 17 by avibootz
0 votes
var workers = [
    { id: 13451, name: 'Axel'},
    { id: 87134, name: 'Blaze'},
    { id: 79372, name: 'Alma'},
    { id: 39810, name: 'Isla'}
];
   

const result = workers.find(({ name }) => name === 'Isla');

console.log(result) 
 
 
   
   
/*
run:
       
{ id: 39810, name: 'Isla' }
 
*/

 




answered Jun 17 by avibootz
...