Looking at a couple of different docs, all I see is when the Map (ECMAScript 6) key is a boolean, string, or integer. Is there a way we could use another customized Object (called with the new CustomObject(x,y) constructor call) to be added as a key?
I am able to add an object as a key, but unable to check if the Map has the said object:
var myMap = new Map();
myMap.set( new Tuple(1,1), "foo");
myMap.set('bar', "foo");
myMap.has(?);
myMap.has('bar'); // returns true
Is there a way around this?
var myMap = new Map();
myMap.set( new Tuple(1,1), "foo");
for(some conditions) {
var localData = new Tuple(1,1); //Use directly if exists in myMap?
map.has(localData) // returns false as this is a different Tuple object. But I need it to return true
}
Mapis one option to implementTuplelookup.Mapare surprising and confusing. In Java, we must provideequals()andhashCode()methods for our classes, and the JavaHashMapclass then works as expected when using keys that are different objects but are equivalent objects (that is, keys can have value semantics).