Hello, I have to do an exercise in which they give me a URL, for example https://www.amazon.es/electronica/b?ie=UTF8&node=599370031
, and make a function that returns an object with the following properties: protocol, hot, query and a params array. So so so
{ "protocolo": "http", "host": "www.amazon.es", "path": "", "query": {""} }
var loc = new URL("http://cv.uoc.edu/webapps/bustiaca/listMails.do?mailId=5848042_774330153&l=181_m4_250_01_t01");
console.log(loc.protocol); // => "http:"
console.log(loc.host); // => "example.com:3000"
console.log(loc.hostname); // => "example.com"
console.log(loc.port); // => "3000"
console.log(loc.pathname); // => "/pathname/"
console.log(loc.hash); // => "#hash"
console.log(loc.search); // => "?search=test"
I have used this function but I don't know how to generate the object. Thanks.
Actually you have almost everything already done, you just need to group it in a function and create the object: