Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

decoDe query string to 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}
 
PREVIOUS NEXT
Tagged: #decoDe #query #string #object #javascript
ADD COMMENT
Topic
Name
1+9 =