War es hilfreich?

Frage

Join Map values into a single string with JavaScript?

JavascriptWeb DevelopmentObject Oriented Programming

You can use the concept of Map(). In JavaScript, map has the key value concept in which key must be unique.

We also need to use the join() method to join Map values. Following is the code −

Example

let queryStringAppendWithURL = new Map();
queryStringAppendWithURL.set("firstParamter", ["name=John", "age=23", "countryName=US"]);
queryStringAppendWithURL.set("secondParamter", ["subjectName=JavaScript", "Marks=91"]);
let appendValue = Array.from(queryStringAppendWithURL.values()).map(value =>
value.join('?')).join('?');
console.log("The appended value is="+appendValue);

To run the above program, you need to use the following command −

node fileName.js.

Here, my file name is demo78.js.

Output

This will produce the following output −

PS C:\Users\Amit\JavaScript-code> node demo78.js
The appended value
is=name=John?age=23?countryName=US?subjectName=JavaScript?Marks=91
raja
Published on 07-Sep-2020 11:31:01
Advertisements
War es hilfreich?
Nicht verbunden mit Tutorialspoint
scroll top