//example of an Object
var person = {
firstName:"John",
lastName:"Doe",
age:50
};
Expected output :
URL : www.domain.com/person?firstName=John&lastName=Doe&age=50
what is the best way to add it in query param ?
I found this method :
getQueryParamURL(url, param) {
let query = '?'
Object.keys(param).forEach((key, i, arr) => {
query += key + '=' + param[key]
if (arr[i + 1]) {
query += '&';
}
})
return url + query
}
Use it :
let personObj = {
firstName:"John",
lastName:"Doe",
age:50
};
let queryUrl = this.getQueryParamURL('www.domain.com/person',personObj )
Object.entries(person).map(k=>k.join("=")).join('&')