Created
October 12, 2018 08:58
-
-
Save jeandcr/c9a54d1c6ac26168f65476d8e48e764e to your computer and use it in GitHub Desktop.
JS Array to URLEncoded
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Extend Array prototype | |
| */ | |
| Array.prototype.toQueryString = function(){ | |
| var out = new Array(); | |
| for(key in this){ | |
| out.push(key + '=' + encodeURIComponent(this[key])); | |
| } | |
| return out.join('&'); | |
| } | |
| /* | |
| * Standalone function | |
| */ | |
| function arrayToQueryString(array_in){ | |
| var out = new Array(); | |
| for(var key in array_in){ | |
| out.push(key + '=' + encodeURIComponent(array_in[key])); | |
| } | |
| return out.join('&'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment