0

I'm rewriting an algorithm I originally wrote in C++, and looking for a similar implementation in JavaScript as what one would generally do in C++:

std::map<<std::string, std::vector<std::string>> my_map_of_vectors;

This is the closest I've got, but I'm struggling...

 var my_map = new Map();
 var array_history = [];

 // below within a for-loop...
 my_map.set(data_blob[row].s_col1,array_history.push({h_col1:data_blob[row].s_col2}));

And then to access the first element of the array, with a known key, I get nothing...

document.writeln(xer_map.get("GG1000").h_col1[0]);

Not sure where to go from here, any help is appreciated!

jparanich
  • 8,372
  • 4
  • 26
  • 34
  • `push` does not return an array. It mutates the array and returns its new length. Not sure why you’re struggling — the [documentation](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/push) is pretty clear on this. – Sebastian Simon Oct 05 '21 at 19:25
  • Thanks. Unsure the backhanded comment was necessary. Maybe because I've programmed in JavaScript all of 3 hours. – jparanich Oct 05 '21 at 19:30

0 Answers0