javascript object find 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: javascript array.find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
Example 4: 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 5: object find javascript
function isBigEnough(element) {
return element >= 15;
}
[12, 5, 8, 130, 44].find(isBigEnough);
Example 6: find in js
The first element that will be found by that function
const f = array1.find(e => e > 10);