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
If you want to do this with a Set, then the object you're searching for has to be the same object that was added, not an anonymous object.
So, you could achieve what you're looking for if it was set up like this:
let myObject = {"name": "a", "value": 0};
let set = new Set([myObject]);
console.log(set.has(myObject));
This is because set.has()
uses SameValueZero()
under the hood.
Here is the spec for set.has()
: http://www.ecma-international.org/ecma-262/6.0/#sec-set.prototype.has
And for SameValueZero()
: http://www.ecma-international.org/ecma-262/6.0/#sec-samevaluezero