Javascript - Global encodeURIComponent() Function

The encodeURIComponent() function encodes a URI component.

Description

The encodeURIComponent() function encodes a URI component.

This function encodes special characters.

It also encodes the following characters: , / ? : @ & = + $ #

Syntax

encodeURIComponent(uri)

Parameter Values

Parameter Require Description
uri Required. The URI to be encoded

Return

A String, representing the encoded URI

Example

Encode a URI:

Demo

var uri = "https://book2s.com/my test.asp?name=json&lang=java";
var res = encodeURIComponent(uri);
console.log(res);

Result