JS对象转URL查询字符串

2020-03-0950次阅读javascriptES6
"use strict";
function objectToQueryString(obj) {
  return Object.keys(obj).map(key=>{
    return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(obj[key]));
  }).join('&');
};
objectToQueryString({
  name: 'Jhon',
  age: 18,
  address: 'beijing'
});

结果为
name=Jhon&age=18&address=beijing

上一篇: js导出Excel表格  下一篇: JS对象转formData对象  

JS对象转URL查询字符串相关文章