This is my solution
arr = location.search.replace('?', '').split('&').map(x => x.split('=')).map(x => {
let keyName = x[0];
let val = x[1];
let object = {};
object[keyName] = val;
return object;
});
obj = {}
arr.forEach(function(x) {
let key = Object.keys(x)[0];
obj[key] = x[key];
});
console.log(obj);
Basicaly with location.search we obtain the right part of a url, after the path (the query params with).
location.search also returns the '?' character, replace with white space, then split whit '&', map and split with '=', for obtain un array like
[['term', 'hello'], ['lang', 'es']]
Then, assemble the object as you wanted
arr = "?safe=active&source=hp&ei=c4Q8XcOPFd3F5OUP7e242Ag&q=hola&oq=hola&gs_l=psy-ab.3..0l5j0i131j0l2j0i131j0.1324.1667..1798...1.0..0.264.744.1j3j1......0....1..gws-wiz.....10..35i39.-_FkFlX_Muw&ved=0ahUKEwiDlaTgytXjAhXdIrkGHe02DosQ4dUDCAU&uact=5".replace('?', '').split('&').map(x => x.split('=')).map(x => {
let keyName = x[0];
let val = x[1];
let object = {};
object[keyName] = val;
return object;
});
obj = {}
arr.forEach(function(x) {
let key = Object.keys(x)[0];
obj[key] = x[key];
});
console.log(obj);