UNPKG

web-utils-super

Version:

前端函数库

28 lines (23 loc) 641 B
/** * * @desc 对象序列化 * @param {Object} obj * @param {String} str 连接符 默认'&' * @return {String} */ function stringfyQueryString(obj, str = '&') { if (!obj) return '' let pairs = [] for (let key in obj) { let value = obj[key] if (value instanceof Array) { for (let i = 0; i < value.length; ++i) { pairs.push(encodeURIComponent(key + '[' + i + ']') + '=' + encodeURIComponent(value[i])) } continue } pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(obj[key])) } return pairs.join(str) } module.exports = stringfyQueryString