js find value in object code example
Example 1: get all entries in object as array hjs
const object1 = {
a: 'somestring',
b: 42
};
for (let [key, value] of Object.entries(object1)) {
console.log(`${key}: ${value}`);
}
Example 2: js array find
var ages = [3, 10, 18, 20];
function checkAdult(age) {
return age >= 18;
}
ages.find(checkAdult);
Example 3: return an object from an array javascript
myArray.find(item => item.isAstronaut)
Example 4: object find javascript
function isBigEnough(element) {
return element >= 15;
}
[12, 5, 8, 130, 44].find(isBigEnough);