I am studying algo & ds. And there are many times we use the map. For example, Leetcode 1 problem, two Sum. We can solve it as below.
var twoSum = function(nums, target) {
let map = new Map();
for (let i = 0; i < nums.length; i ++) {
if (map[nums[i]] >= 0) {
return [map[nums[i]], i]
}
map[target-nums[i]] = i
}
return [-1, -1];
};
But I am not sure what's the difference between
let map = {};
and
let map = new Map();
Please enlighten me.
Thank you.