You can convert the object to a string. The type of keys in a javascript object should be a string
Property names must be strings. This means that non-string objects
cannot be used as keys in the object. Any non-string object, including
a number, is typecasted into a string via the toString method.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_Accessors
You can find the same example in the above link.
c[<some_func_to_convert_obj_to_string(a1)>]=2
So If you want to use the object as a key you need to convert the object to a unique string.. and there are many answers here for that Converting object to string . As Steven Wexler pointed out that JSON.stringify is non deterministic it is better not to use it. I am not copying down those functions again because there is a dedicated SO question for that.