Looking to create a unique datatype or object in JavaScript that allows access by both index and key, as well as having a length property to display the number of items in the datatype. Something along the lines of:
MyDataType[0].name="John"
MyDataType[0].salary="over 1k"
If I were to write:
MyDataType['John'].salary //I should get "over 1k"
And also if I were to write:
MyDataType[0].salary //I should also get "over 1k"
I would like it to include:
MyDataType.length //should return 1
Is this achievable?
I experimented with Proxy and it worked smoothly for the index/key aspect but lacked a length property. When using an array, I had access to index and length properties but couldn't use keys.
Appreciate any guidance you can provide. Thank you!