I am trying to get the objects name in JS. I am trying to avoid doing loops for better code reading. As I am new to the JS code I am not sure what to do.
const collection = [
{
name: 'foo',
value: 12,
},
{
name: 'bar',
value: 5,
},
]
const fa = (collection) = {
//theName should return just the name value so 'bar'
let theName = Object.keys(collection).find(value => value < 10).name;
console.log(theName);
}
Thanks to anyone who could help.
fa = collection => collection.find(({ value }) => value < 10)?.name?