把 s="A,B,C"变成[{id: 1,title: 'A',},{id: 2,title: 'B',},{id: 3,title: 'C'}],我的方法是ss = s.split(",");console.log(ss)arr = [];for (var i=1; i<=ss.length; i++) {a=ss[i]arr[i]['id']=i;arr[i]['title']=a;}console.log(arr)但是还是报错
1 回答
暮色呼如
TA贡献1853条经验 获得超9个赞
let s = "A,B,C";
let arr = s.split(',').map((title, id) => {
id++;
return { id, title };
});
添加回答
举报
0/150
提交
取消