function makeQueryString(params) {
    let result = []
    for (const key in params) {
        if (!key) {
            continue
        }
        const values = params[key]
        for (const value of Array.isArray(values) ? values: [values]) {
            if (!value) {
                continue
            }
            result.push(encodeURI(key) + '=' + encodeURI(value))
        }
    }
    return result.join('&')
}

console.log(makeQueryString({'foo': '1', 'bar': '2', 'baz': ['a', 'b']}))

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: