search an object javascript 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)
//Object { val: "bb" }
//Use this for finding an item inside an object.
Example 2: javascript array.find
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
// expected output: 12
Example 3: return an object from an array javascript
myArray.find(item => item.isAstronaut)