I'm having some troubles while checking if a map already has an object as key.
e.g.
const myMap: Map<MyObject1, MyObject2> = new Map<MyObject1, MyObject2>();
I also defined an equals function in MyObject1 class
equals(other: ThreatAgentMgm): boolean {
return other.id === this.id;
}
but myMap.has(myObject1)
is always false.
I read theat the has method is based on the === operator, should I define something else in MyObject1 class?
Since every JSON object in the end is just a string, I ended up using the JSON.stringify(myObject) as the key of the Map, and a couple of values (MyObject1, MyObject2) as the actual value. This way I'm able to get the desired value in time O(1) while keeping the key object available, without the need of parsing the JSON again or worst, retrieving it from the DB once again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With