w3resource

JavaScript: decodeURIComponent functions

Description

The decodeURIComponent function is used to decode a Uniform Resource Identifier (URI) component previously created by encodeURIComponent.

Syntax

decodeURIComponent(encodedURI)

Parameters

encodedURI: An encoded component of a Uniform Resource Identifier.

Example of decodeURIComponent() function

In the following web document decodeURIComponent() function is used to decode a Uniform Resource Identifier (URI) component previously created by encodeURIComponent.

JavaScript Code:

url1 = "https://w3resource.com/xyz=http%3A%2F%2Fmyw3r.com%2Fx%3D31%26y%3D21&xyz3=45"; 
//Lets decode url1
console.log(decodeURIComponent(url1));

View the example in the browser

Live demo:

See the Pen decodeURIComponent-function-1 by w3resource (@w3resource) on CodePen.


Previous: JavaScript: encodeURIComponent functions
Next: JavaScript Object



JavaScript: Tips of the Day

Returns all unique values of an array, based on a provided comparator function

Example:

const tips_uniqueElementsBy = (arr, fn) =>
  arr.reduce((acc, v) => {
    if (!acc.some(x => fn(v, x))) acc.push(v);
    return acc;
  }, []);

console.log(tips_uniqueElementsBy(
  [
    { id: 0, value: 'p' },
    { id: 1, value: 'q' },
    { id: 2, value: 'r' },
    { id: 1, value: 's' },
    { id: 0, value: 't' }
  ],
  (a, b) => a.id == b.id
)); 

Output:

[[object Object] {
  id: 0,
  value: "p"
}, [object Object] {
  id: 1,
  value: "q"
}, [object Object] {
  id: 2,
  value: "r"
}]