JavaScript get query string | Current URL example

  • by

Use URLSearchParam API to get query string in JavaScript. It’s supported by all modern browsers. But you have to first get the full query string via the property.

 // "?post=1234&action=edit"

var urlParams = new URLSearchParams(;

console.log(urlParams.has('post')); // true

How to get query string Example

For current URL use it:-

const params = new URLSearchParams(
for (const param of params) {

How it will work if we have a URL like this:-


Complete code


		const params = new URL("").searchParams;

		for (const param of params) {




JavaScript get query string

Do comment if you have any suggestions on this JS URL code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.