Get URL Parameters in JavaScript | URLSearchParams

Get URL Parameters in JavaScript | URLSearchParams


Get URL Parameters in JavaScript | URLSearchParams

Get parameters from URL in JavaScript. In this video we will learn about getting query string parameters or URL variables in JavaScript and parse (resolve / settle / find solution to) URL parameters. In some cases, we need to get parameters from URL. These can be called as URL parameters, query string parameters or URL variables. We can do that in JavaScript.

index.html?name=john\u0026age=20

In this name and age are parameters and after isEquals sign is their value. There is window.location in JavaScript. If we expand window.location log in console, we see our parameters in front of search. We can store it in a variable and pass it to JavaScript URLSearchParams.

From there we can use get method for URLSearchParams to separate URL parameters. We will parse (resolve / settle / find) the query string’s parameters using URLSearchParams. Get method will return the first value associated with the given search parameter. Now we can log these parameters individually or use these in our code. This is how we can get URL parameters in JavaScript. It can be used to get passed values from URL in JavaScript.

If you are new to the channel, subscribe to learn more about web development, web application development, JavaScript, related tools and technologies.

Thank You!
👍 LIKE VIDEO
👊 SUBSCRIBE
🔔 PRESS BELL ICON
✍️ COMMENT

Channel:    / webstylepress  
Website: https://www.webstylepress.com
FaceBook: https://www.facebook.com/webstylepress
Twitter: https://twitter.com/webstylepress
GitHub: https://github.com/webstylepress
#WebStylePress #JavaScript #JS #URLSearchParams #URLParameters #ParseURL #tutorial #webDevelopment


Content

0.8 -> welcome to web style press in some  cases we need to get parameters from url  
7.36 -> like this name and age value for name and age  parameters with question sign after the actual url  
17.12 -> these can be called as url parameters  query string parameters or url variables  
24.72 -> we can get these parameters or get values for  these parameters in javascript this is our url  
33.68 -> this is our page then we have got slash  in question sign and the name is equal  
38.96 -> to john and age is equal to 20. name and age are  parameters and after is equal sign is their value  
52.88 -> there is window.location  in javascript let's log it
60.72 -> save and this is window location if we expand it  
67.36 -> we see our parameters in front of search search  name is equal to john and a is equal to 20.  
76.88 -> we logged window dot location let's store  window.location.search in a variable const  
86.72 -> my keys values is equal to window dot location  dot search and then console log my keys values
100 -> save keys and values name is equal  to john and age is equal to 20.  
107.44 -> from window location search we have extracted  these now let's log these parameters  
114.72 -> separately we will pause query strings  parameters using url search params  
123.36 -> this is url search params and parsing  means to resolve to settle or to find  
130.88 -> we will resolve the query strings  parameter using url search parents
139.52 -> so url params new url search params
147.12 -> and we will use window.location.search  inside it this one  
154.8 -> after this we can call get method on the result
161.12 -> url search params get method get method  will return the first value associated  
167.92 -> with the given search parameter there are  other methods for url search params as well  
175.04 -> as you can see here these are  methods dot append dot delete  
179.68 -> dot entries dot for h dot get dot get all dot  has dot keys dot set sort to string and values
193.6 -> so url params dot get we know  we have got this name in the url
207.04 -> let's store it in a variable
210.8 -> param1 and then this is our param2  and second thing we want to get is age
222.08 -> now all we have to do is to console log these two  params save and we've got name john and age 20.
239.2 -> this is all we need to get  url parameters in javascript  
243.92 -> so this is how we can get url parameters in  javascript it can be used to get past values  
250.96 -> from url in javascript for more you  can have a look at url search params  
257.28 -> from mdn web docs okay i hope it helped like share  subscribe and i will see you in the next video

Source: https://www.youtube.com/watch?v=CZP1iQFQjEY