Javascript object/array as key for Map

Viewed 495

What's the best way to use 2 string variables as the key for a Map?

const map = new Map();
map.set(['a', 'b'], 5);
map.get(['a', 'b']); //undefined

Creating a reference to [v1, v2] and using that as key is not an option for my case.

Is the only option to combine the two variables with a delimiter? (will be messy if the string variables can potentially contain the delimiter character).

1 Answers
Related