Answers for "find object in array by value js"

18

js find object from value in array

let arr = [
    { name:"string 1", value:"this", other: "that" },
    { name:"string 2", value:"this", other: "that" }
];

let obj = arr.find(o => o.name === 'string 1');

console.log(obj);
Posted by: Guest on May-08-2020
7

javascript find object in array

myArray.findIndex(x => x.id === '45');
Posted by: Guest on September-15-2020
2

how to find id in array javascript

//The find() method returns the value of the first element in the provided array that satisfies the provided testing function.
const array1 = [5, 12, 8, 130, 44];

const found = array1.find(element => element > 10);

console.log(found);
// expected output: 12
Posted by: Guest on December-03-2019
0

javascript find item in array of objects

var __POSTS = [ 
	{ id: 1, title: 'Apple', description: 'Description of post 1' }, 
	{ id: 2, title: 'Orange', description: 'Description of post 2' }, 
	{ id: 3, title: 'Guava', description: 'Description of post 3' }, 
	{ id: 4, title: 'Banana', description: 'Description of post 4' }
];

var __FOUND = __POSTS.find(function(post, index) {
	if(post.title == 'Guava')
		return true;
});

// On success __FOUND will contain the complete element (an object)
// On failure it will contain undefined  
console.log(__FOUND); // { id: 3, title: 'Guava', description: 'Description of post 3' }
Posted by: Guest on May-31-2020

Code answers related to "find object in array by value js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language