🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
将 str = "1,2,3",  str2 ="ann,lili,john" 转为:arr = \[{id: 1,name: 'ann'},{id: 2, name: 'lili'},{id: 3,name: 'john'}\]; 代码如下: ``` let arr = []; let s1 = str.split(','); s.forEach((item, i)=>{ let obj = {}; obj.id = item; arr.push(obj) }) let s2 = str2.split(',') s2.forEach((item, i)=>{ arr[i].name = item; }) ```