Skip to content

Instantly share code, notes, and snippets.

@ayamomiji
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayamomiji/0f47a41546d07827d1a7 to your computer and use it in GitHub Desktop.
Save ayamomiji/0f47a41546d07827d1a7 to your computer and use it in GitHub Desktop.
# 不考慮重複 key 和無 value 的情況
parseQS = (qs = location.search) ->
object = {}
pairs = qs.substring(1) # 去除前置 ? 字元
.split('&') # 變成一堆 oo=xx 字串
for pair in pairs
[key, value] = pair.split('=')
object[key] = value
object
parseQS('?noel=yoona&foo=bar&yoona&foo=bar')['noel'] # => yoona
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment