const search = window.location.search;
const result = search.slice(search.indexOf('?') + 1).split('&').reduce((params, hash) => {
let [key, val] = hash.split('=')
let value = decodeURIComponent(val);
let b = ['true', 'false'];
if (!isNaN(Number(value))) {
value = +value
} else if (b.includes(value)) {
value = !!value
}
return Object.assign(params, {
[key]: value
})
}, {})
console.log(result)
const search = window.location.search;
const result = search.slice(search.indexOf('?') + 1).split('&').reduce((params, hash) => {
let [key, val] = hash.split('=')
let value = decodeURIComponent(val);
if (!isNaN(Number(value))) {
value = +value
} else if (Boolean(value)) {
value = !!value
}
return Object.assign(params, {
[key]: value
})
}, {})
console.log(result)