「JavaScript」decodeURIComponent関数でエンコードされた文字列を元の文字列に戻す

環境
Google Chrome 105.0.5195.102
Windows 10 Home 64bit

書式
decodeURIComponent(encodedURI)
encodedURI エンコードされた URI の構成要素です。
encodeURIComponent関数でエンコードされた文字列を元の文字列に戻します。

返値
エンコードされた統一資源識別子 (URI) の構成要素をデコードしたものを表す新しい文字列です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const strA ="%E3%81%82%E3%81%84%E3%81%86456";
console.log(decodeURIComponent(strA));
const strB = "study%20skill%20123";
console.log(decodeURIComponent(strB));
const strA ="%E3%81%82%E3%81%84%E3%81%86456"; console.log(decodeURIComponent(strA)); const strB = "study%20skill%20123"; console.log(decodeURIComponent(strB));
const strA ="%E3%81%82%E3%81%84%E3%81%86456";
console.log(decodeURIComponent(strA));

const strB = "study%20skill%20123";
console.log(decodeURIComponent(strB));

実行結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
> "あいう456"
> "study skill 123"
> "あいう456" > "study skill 123"
> "あいう456"
> "study skill 123"

 

JavaScript

Posted by arkgame