How to get query string parameter values in JavaScript?
Hello everyone! I'm a beginner in JavaScript and I've encountered a task: I have a URL like `https://example.com/page?name=John&age=30&city=NewYork`. I need to get the parameter values from the query string, for example, to extract the username (`name`) or age (`age`). I tried parsing the URL manually using `split('?')` and `split('&')`, but it seems very cumbersome and unreliable, especially if the values contain special characters (e.g., `name=John%20Doe`). I also heard that you can use `window.location.search`, but I don't understand how to extract a specific parameter from it. Please advise how to correctly and simply get query string values in JavaScript? Preferably with code examples so I can apply them right away. Thanks in advance!
<<>>
Main solution: URLSearc
No answers yet.
Log in to leave an answer
Blogs
Monorepository with Java: Code Organization and Best Practices
Functional Programming in Go: Advanced Techniques and Examples
Go for Machine Learning: Capabilities and Limitations in Practice
Swift in 2025: Overview of New Features and Practical Code Examples