0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[ES6]JavaScriptでGETパラメーターを取得する

Last updated at Posted at 2019-01-03

元記事 JavaScriptでGETパラメーターを取得する をES6で書いてみた。

JavaScript
/**
 *  GETパラメータを配列にして返す
 *  
 *  @return     パラメータのObject
 *
 */
const getUrlVars = () => {
    const vars = {}; 
    location.search.substring(1).split('&').forEach(param => {
        const [key, ...val] = param.split('=');
        if (key !== '') {
            vars[key] = decodeURI(val.join('='));
        }
    });
    return vars;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?