can-param
Serialize an object or array into a query string.
param(object)
Serializes an object or array into a query string useful for making Ajax requests. param
handles nested objects and arrays. It uses encodeURIComponent
to
escape values and keys.
import param from "can-param";
param( { foo: "bar" } ); //-> "foo=bar"
param( { foo: [ "bar", "baz" ] } ); //-> "foo[]=bar&foo[]=baz"
param( { foo: { bar: "baz" } } ); //-> "foo[bar]=baz"
param( { foo: "bar & baz" } ); //-> "foo=bar+%26+baz"
This is exported as param
on can-namespace.
Parameters
- object
{Object}
:An object or array.
Returns
{String}
:
The params formatted into a form-encoded string.
Try it
Use this JS Bin to play around with this package: