练习:对象转成字符串;字符串转成对象
let phone = { name: "小米10", color: 红色, size: 1000 * 200 * 500, price: 2999 } "name=小米10&color=红色&size=1000*200*500&price=2999"
1、对象转成字符串 (方式1) let sum=[ ] for(let key in phone) {sum.push(key+'='+phone[key])} let a=sum.join('&') console.log(a) (方式2) console.log(Object.keys(phone).map(k=>[k,phone[k]].join ('=’).join('&')) 2、字符串转成对象 let num={ } v.split('&'),forEach(l=>{let a=l.split('=') num[a[0]]=a[1]}) console.log(num)