

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
URLSearchParams sort & toString() in Node
Introduction to sort()
This function sorts the existing name-value pairs by their names. The sorting is done inplace. It used stable algorithm for sorting.
Syntax
URLSearchParams.sort(name);
It will return a sorted order of elements (name-value pairs) by sorting them based on their key value.
Example
// Defining the parameters as a constant const params = new URLSearchParams( 'lastName=Chan&midName=abc&firstName=John'); // Sorting the parameters params.sort(); console.log(params.toString());
Output
firstName=John&lastName=Chan&midName=abc
Example
// Defining the URL as a constant const params = new URLSearchParams( 'z=5&a=2&d=4&c=3&a=1'); // Sorting the parameters params.sort(); console.log(params.toString());
Output
a=2&a=1&c=3&d=4&z=5
Introduction to toString()
This function converts the urlSearchParameter to string. Characters are encoded when required.
Syntax
URLSearchParams.toString();
It returns the URL after converting it into string. Any unicode character will be encoded.
Example
const params = new URLSearchParams( 'lastName=Chan&midName=abc&firstName=John'); console.log(params.toString());
Output
lastName=Chan&midName=abc&firstName=John
Example
// Defining the URL as a constant const params = new URLSearchParams( 'z=5&a=2&d=4&c=3&a=1'); // Printing url params in string type console.log(params.toString());
Output
z=5&a=2&d=4&c=3&a=1
- Related Questions & Answers
- URLSearchParams entries & forEach in Node
- URLSearchParams values & keys() in Node
- Introduction to URLSearchParams API in Node.js
- Integer toString() in Java
- Java toString() method.
- First and last child node of a specific node in JavaScript?
- ShortBuffer toString() method in Java
- Provider toString() method in Java
- Duration toString() method in Java
- MonthDay toString() Method in Java
- Instant toString() method in Java
- LocalDate toString() method in Java
- LocalDateTime toString() method in Java
- LocalTime toString() method in Java
- Int64.ToString() Method in C#
Advertisements