Object类型转为query字符串类型


将{a: 1, b:2, c:3} 转为a=1&b=2&c=3字符串

function changeQuery(obj) {
      if (typeof obj !== 'object' || Array.isArray(obj)) return
      const result = []
      for (const key in obj) {
        result.push(`${key}=${obj[key]}`)
      }
      return result.join('&')
}
const params = {
    a: 1,
    b: 2,
    c: 3
}
changeQuery(params)

相关