- Instant help with your JavaScript coding problems

Get parameter from URL in JavaScript

Question:
How to get parameter from URL in JavaScript?
Answer:
// https://testsite.com/users?page=10&pagesize=25&order=asc
const urlParams = new URLSearchParams(window.location.search);
const pageSize = urlParams.get('pageSize');
Description:

The URLSearchParams interface defines utility methods to work with the query string of a URL. The URLSearchParams.get() returns the first value associated with the given search parameter.

Share "How to get parameter from URL in JavaScript?"