Is it possible to use the javascript \"Set\" object to find an element with a certain key? Something like that:
let myObjects = [{\"name\":\"a\", \"value\":0
Actually a response to Efficiently find an item in a Set but they've closed it as a duplicate #ftw
An alternative approach:
class ArraySet extends Set {
find(predicate) {
for(var x of this)
if (predicate(x)) return x;
return undefined;
},
... other Array.prototype stuff here
}
const things = new ArraySet([
{ x: 1 },
{ y: 2 }
]);
const found = things.find(item => item.y === 2);