// 用原生方法将字符串转换成键值对的对象形式进行存储
<script>
var str = 'username=zhangsan&password=123456'
var arr = str.split('&');
console.log(arr);
var obj = {};
for (var i = 0; i < arr.length; i++) {
var newArr = arr[i].split('=')
obj[newArr[0]] = newArr[1];
}
console.log(obj);
</script>
02-03
2161
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
01-09
2319
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)