find object js code example
Example 1: find item in object js
const object1 = {
a: {val: "aa"},
b: {val: "bb"},
c: {val: "cc"}
};
let a = Object.values(object1).find((obj) => {
return obj.val == "bb"
});
console.log(a)
Example 2: javascript find object by property in array
myObj = myArrayOfObjects.find(obj => obj.prop === 'something');
Example 3: how to find id in array javascript
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 4: js find value in array
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 5: return an object from an array javascript
myArray.find(item => item.isAstronaut)
Example 6: object find javascript
function isBigEnough(element) {
return element >= 15;
}
[12, 5, 8, 130, 44].find(isBigEnough);