I am going to use an object as a HashMap in JavaScript. I want to add a key which would be a new property for that object and give it a value. Then, after a while, take that value and do stuff on that.
I want to extract all the links. Save the URL of the page as the key and the array of its links as the value. Therefore, I have wrote following lines.
let's say the URL of the page is http://www.google.com
var test = {};
var links = document.getElementsByTagName('a');
var currentURL = document.URL;
test.currentURL = links;
Here, my expectation was that I have a key which is http://www.google.com together with its value which is an array contains all the links on the page. After that, I wanted to write following line
var inProcessURL = allTheURLs[0].url;
var arrayOfLinks = test.inProcessURL;
and then work based on this array. But, I found that in the first part, I am creating the key which is 'currentURL' not 'http://www.google.com' which causes me to not be able to refer to it later on.
Is there any way based on which I can do my goal in JavaScript or I have to change my data structure from an Object to the Array?
I don't know which key I am going to refer to at different step. They would be something extracted from an array.