I need to have a equivalent of hash map in javascript. It seems Map is the right choice. However, I need to set the value of each pair in the Map as an array. For example, myMap: key1: param1 value1: [1, 2, 3]
key2: param2 value2: [3, 4, 5]
I looked at the following page, but couldn't figure out how to do that. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/has
The purpose of doing this is I'm trying to extract the data in a tale on a HTML page. Basically, I want to use a hash map to organize all the data in the table. So each column name will be the key of the hash map, and the corresponding values in the column will be the value corresponding to that key.
Follows are the codes I'm trying with:
function (data) {
$.each(data, function (key, value) {
tempData += '<tr>';
tempData += '<td>' + value.name + '</td>';
tempData += '<td>' + value.value + '</td>';
//check whether the key already exists in the map
if (measurementDataMap.get(value.name) == undefined) {
//if the key doesn't exist, the value points to an empty array
measurementDataMap[value.name] = [];
}
measurementDataMap[value.name].push(value.value);
});
I can't figure out how to create an empty array for the value of a new pair. Thanks!
let mything = { key1 : [1,2,3,4], key2: ['a', 'b', 'c', 'd']}is already perfectly fine, and perfectly working, Javascript.