ใช้ Map เก็บค่า แล้ว Array.from(), map(), join() รวมเป็นสตริง
ตัวอย่างโค้ด
let queryStringAppendWithURL = new Map();
queryStringAppendWithURL.set("firstParameter", ["name=John", "age=23", "countryName=US"]);
queryStringAppendWithURL.set("secondParameter", ["subjectName=JavaScript", "Marks=91"]);
let appendValue = Array.from(queryStringAppendWithURL.values())
.map(value => value.join('?'))
.join('?');
console.log("The appended value is=" + appendValue);
วิธีรันโปรแกรม
ใช้คำสั่ง node fileName.js (เช่น node demo78.js)
ผลลัพธ์
The appended value is=name=John?age=23?countryName=US?subjectName=JavaScript?Marks=91