i was given a homework problem to be able to create a query string based on certain parameters in an array? I am still fairly new to javascript so have some success with it but would appreciate if someone can check my code please. Thank you to everyone in advance.
I am using forEach to loop through the array to get the values and using string concatenation to get some url. I have made a sample codepen for it.
https://codepen.io/anon/pen/pmRXzg
let Person = {
name: ['Sam', 'Daisy'],
food: ['banana', 'Apple']
}
let handler = Object.entries(Person)
handler.forEach(function(element) {
console.log(element)
})
let myUrl = Object.entries(handler).map(key => key + '=' +
handler[key]).join('&')
let visitUrl = "http://someURLString/?" + myUrl
console.log(myUrl)
console.log(visitUrl)
How can i get my final result to look like
someUrlString/?name=Sam,Daisy&food=banana,apple