In the URLSearchParams interface, the values() method returns an iterator which allows us to iterate through all the values present in the object
Syntax:
searchParams.values();
Return: Returns an ES6 Iterator over the values of each name-value pair.
Example 1: In this example, we will see the use of urlSearchParams.values().
javascript
// Create a test URLSearchParams object const searchParams = new URLSearchParams( "keyA=valueA&keyB=valueB" );
// Display the values for (let value of searchParams.values()) {
console.log(value);
} |
Output:
valueA valueB
Example 2: To create parameters directly
javascript
// Create a test URLSearchParams object const searchParams = new URLSearchParams( "name = deepak & age = 18 " );
// Display the values for (let value of searchParams.values()) {
console.log(value);
} |
Output:
deepak 18
Supported Browsers:
- Google Chrome
- IE
- Edge
- Opera
- Apple Safari