encodeURIComponent

encodeURIComponent

Description

encodeURIComponent(string uriComponent)

Parameters

Name Description Type Default Optional
uriComponent string No

Examples

Example #1 – encodeURIComponent example

Encodes a url parameter.

var uriComponent = encodeURIComponent('{"foo": ["bar"]}'); console.log(uriComponent); // %7B%22foo%22:%20%5B%22bar%22%5D%7D

If used on a url, it will encode it as a parameter.

var uriComponent = encodeURIComponent('http://example.com/'); console.log(uriComponent); // http%3A%2F%2Fexample.com%2F

See also

External references