Decode Query String ke Object JavaScript

type mapping = {
  [key: string]: string
}

function url_to_object(url: string): mapping {
  const data: {[key: string]: any} = {}
  url
    .replace(/\/\?/, '')
    .split('&')
    .map(x => x.split('='))
    .forEach(x => {
      data[x[0]] = x[1]
    })
  return data;
}

url_to_object('id=4&second=3')	// {id: 4, second: 3}
Frustrated Developer