Say I have a couple of objects that are on the heap:
const x = {foo:'bar'};
const y = {foo:'bar'};
const z = {foo:'bar'};
is there a way to put these in hash like so:
const c = {x: 'yolo', y: 'rolo', z: 'cholo'};
the only way this might work is if x y and z were represented by their locations in memory. I think this is possible in some languages, is it possible with JS?
Yes, you can do this with an ES6 Map:
const c = new Map([
[x, 'yolo'],
[y, 'rolo'],
[z, 'cholo'],
]);
console.log(c.get(x));
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