@@ -529,7 +529,8 @@ The `URLSearchParams` object provides read and write access to the query of a
529529four following constructors.
530530
531531``` js
532- const URL = require (' url' ).URL ;
532+ const { URL , URLSearchParams } = require (' url' );
533+
533534const myURL = new URL (' https://example.org/?abc=123' );
534535console .log (myURL .searchParams .get (' abc' ));
535536 // Prints 123
@@ -542,6 +543,24 @@ myURL.searchParams.delete('abc');
542543myURL .searchParams .set (' a' , ' b' );
543544console .log (myURL .href );
544545 // Prints https://example.org/?a=b
546+
547+ const newSearchParams = new URLSearchParams (myURL .searchParams );
548+ // The above is equivalent to
549+ // const newSearchParams = new URLSearchParams(myURL.search);
550+
551+ newSearchParams .append (' a' , ' c' );
552+ console .log (myURL .href );
553+ // Prints https://example.org/?a=b
554+ console .log (newSearchParams .toString ());
555+ // Prints a=b&a=c
556+
557+ // newSearchParams.toString() is implicitly called
558+ myURL .search = newSearchParams;
559+ console .log (myURL .href );
560+ // Prints https://example.org/?a=b&a=c
561+ newSearchParams .delete (' a' );
562+ console .log (myURL .href );
563+ // Prints https://example.org/?a=b&a=c
545564```
546565
547566#### Constructor: new URLSearchParams()
0 commit comments