javascript
JavaScript Query String
Generate the URL query string by passing Objects
const params = { name: 'John', age: 30, profession: 'Developer' };
const queryString = Object.entries(params)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&');
console.log(queryString); // name=John&age=30&profession=Developer
Output
name=John&age=30&profession=Developer
Was this helpful?
Similar Posts
- Query selectors in Javascript
- Create random string in Javascript
- indexOf and lastIndexOf a string in javascript
- Remove last character of a string in Javascript
- Get first 10 words from string javascript
- Remove new line separator from start and end positions of string in Javascript
- Calculate the frequency of characters in a string using Javascript