Answers for "Search from array of objects in javascript"

18

find particular object from array in js

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
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
1

find particular object from array in js

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

let obj = arr.find((o, i) => {
    if (o.name === 'string 1') {
        arr[i] = { name: 'new string', value: 'this', other: 'that' };
        return true; // stop searching
    }
});

console.log(arr);
Posted by: Guest on May-08-2020
1

search an array of objects with specific object property value

// MDN Ref:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/find

var result = jsObjects.find(obj => {
  return obj.b === 6
});
Posted by: Guest on May-25-2020
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
0

javascript how to search an array of objects for a particular field value

var result = jsObjects.find(obj => {
  return obj.b === 6
});
Posted by: Guest on March-04-2021

Code answers related to "Search from array of objects in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language