Skip to content

Instantly share code, notes, and snippets.

@ahkohd
Created April 15, 2019 17:25
Show Gist options
  • Save ahkohd/92c3dedb01e04c58cd1f9d0a229136a2 to your computer and use it in GitHub Desktop.
Save ahkohd/92c3dedb01e04c58cd1f9d0a229136a2 to your computer and use it in GitHub Desktop.
function ObjectToUrlEncode(data)
{
return Object.entries(data).reduce((accumulator, current) => {
return `${accumulator}&${current[0]}=${current[1]}`;
}, '').substring(1);
}
console.log(ObjectToUrlEncode({name: "victor", age: 12, line: 13}));
// OUTPUT: "name=victor&age=12&line=13"
@ahkohd
Copy link
Author

ahkohd commented Apr 15, 2019

A simple snippet that converts Javascript object to URL-Encode. A JSBin example
https://jsbin.com/soqifeyavo/edit?html,js,console,output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment