Related Articles

Related Articles

Node | URLSearchParams.append()
  • Last Updated : 29 May, 2019

In URLSearchParams interface, the append() method adds a key/value pair specified by user.
Syntax:

URLSearchParams.append(name, value)

Parameters:
name – Input the parameter name to append
value – Input the parameter value to append

Example1:

filter_none

edit
close

play_arrow

link
brightness_4
code

let url = new URL('https://example.com?par=1&par1=3');
let params = new URLSearchParams(url.search.slice(1));
  
//Add a second par parameter.
params.append('bar', 5);
console.log(url);

chevron_right


Output:

https://example.com?par=1&par1=3&bar=5

Example2:



filter_none

edit
close

play_arrow

link
brightness_4
code

let url = new URL('https://example.com?par=1');
let params = new URLSearchParams(url.search.slice(1));
  
//Add a second par parameter.
params.append('bar', 2);
console.log(url);

chevron_right


Output:

https://example.com?par=1&bar=2

Supported Browsers:

  • Google Chrome
  • IE
  • Edge
  • Opera
  • Apple Safari

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :