Yogesh Chauhan's Blog

12 URLSearchParams methods in JavaScript

in JavaScript on February 7, 2021

1. append()

This method appends a specified key/value pair in URL query string (appends at the end).

2. delete()

This method deletes the specified search parameter and all its associated values.

3. entries()

This method returns an iterator that allows iteration through all key/value pairs in the object.

4. forEach()

This method allows iteration as well but via a callback function.

5. get()

This method returns the value related to the defined search parameter but only the first matched value.

6. getAll()

This method returns ALL the values related to the defined search parameter.

7. has()

This method returns true if the parameter with the specified name exists and false if it doesn’t exist.

8. keys()

This methods allows to iterate over the object as well but it only allows iteration through keys.

9. set()

This method changes the value related to the search parameter to the provided value.

If there are multiple matching values, it will delete the other values.

It will create the search parameter if it doesn’t exist.

10. sort()

This method sorts all key/value pairs as per the unicode code points of the keys.

This method will maintain the relative order between key/value pairs with equal keys.

11. toString()

This method returns a query string.

12. values()

This is opposite to the keys() method. This methods allows to iterate over the object through values.

Source: MDN

Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to avoid element shift on border change while hovering in CSS?CSSHow to create a Star Ratings using CSS?CSSConditional operator in JavaScript (aka ternary operator)JavaScriptThe difference between Class declarations and Class expressions in JavaScriptJavaScriptWhat is Hoisting in JavaScript?JavaScriptWordPress: How to print ACF repeater field values?WordPress