function URLParams(search) { search = search || location.search let result = {} if (typeof URLSearchParams === 'function') { const searchEntries = new URLSearchParams(search) for (const [key, value] of searchEntries) { result[key] = value } } else { const paramLists = search.replace('?', '').split('&') for (const param of paramLists) { const [key, value] = param.split('=') result[key] = value } } return result } console.log(URLParams('?a=1&d=1'))