The encodeURIComponent() function encodes a URI component.
The encodeURIComponent() function encodes a URI component.
This function encodes special characters.
It also encodes the following characters: , / ? : @ & = + $ #
encodeURIComponent(uri)
Parameter | Require | Description |
---|---|---|
uri | Required. | The URI to be encoded |
A String, representing the encoded URI
Encode a URI:
var uri = "https://book2s.com/my test.asp?name=json&lang=java"; var res = encodeURIComponent(uri); console.log(res);