Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1031902 of URLSearchParams.toString()

  • Revision slug: Web/API/URLSearchParams/toString
  • Revision title: URLSearchParams.toString()
  • Revision id: 1031902
  • Created:
  • Creator: rolfedh
  • Is current revision? Yes
  • Comment Editorial review. No changes.

Revision Content

{{ApiRef("URL API")}}{{SeeCompatTable}} 

The toString() method of the {{domxref("URLSearchParams")}} interface returns a string containg a query string suitable for use in a URL.

Syntax

URLSearchParams.toString()

Returns

A string.

Example

let url = new URL('https://example.com?foo=1&bar=2');
let params = new URLSearchParams(url.search.slice(1));

//Add a second foo parameter.
params.append('foo', 4);
console.log(params.toString());
//Prints 'foo=1&bar=2&foo=4'.

Specifications

Specification Status Comment
{{SpecName('URL', '#urlsearchparams-stringification-behavior', "toString()")}} {{Spec2('URL')}} Initial definition. Appears in the IDL as stringifier.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatChrome(49.0)}}        
Feature Android Android Webview Firefox Mobile (Gecko) Firefox OS IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatNo}} {{CompatChrome(49.0)}}           {{CompatChrome(49.0)}}

See also

Revision Source

<p>{{ApiRef("URL API")}}{{SeeCompatTable}}&nbsp;</p>

<p>The <strong>toString() </strong>method of the {{domxref("URLSearchParams")}} interface returns a string containg a query string suitable for use in a URL.</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
URLSearchParams.toString()</pre>

<h3 id="Returns">Returns</h3>

<p>A string.</p>

<h2 id="Example">Example</h2>

<pre class="brush: js">
let url = new URL('https://example.com?foo=1&amp;bar=2');
let params = new URLSearchParams(url.search.slice(1));

//Add a second foo parameter.
params.append('foo', 4);
console.log(params.toString());
//Prints 'foo=1&amp;bar=2&amp;foo=4'.</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('URL', '#urlsearchparams-stringification-behavior', "toString()")}}</td>
   <td>{{Spec2('URL')}}</td>
   <td>Initial definition. Appears in the IDL as <code>stringifier</code>.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<div>{{CompatibilityTable}}</div>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>Firefox OS</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>&nbsp;</td>
   <td>{{CompatChrome(49.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>Other URL-related interfaces: {{domxref("URL")}}, {{domxref("URLUtils")}}.</li>
 <li><a href="https://developers.google.com/web/updates/2016/01/urlsearchparams?hl=en">Google Developers: Easy URL manipulation with URLSearchParams</a></li>
</ul>
Revert to this revision