多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
``` //唯一ID生成 function generateUUID() { var d = new Date().getTime(); var uuid = 'xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { var r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16); }); return 'CN'+uuid; }; var arr = [ { "code": "语文", "name": "小米", "partNo": "" }, { "code": "数学", "name": "小米", "partNo": "01.00.02" }, { "code": "语文", "name": "小米", "partNo": "01.00.02" }, { "code": "语文", "name": "小米", "partNo": "" }, { "code": "数学", "name": "小米", "partNo": "01.00.02" }, { "code": "数学", "name": "小米", "partNo": "01.00.01" }, ] var res = []; var narr = []; for (var i = 0; i < arr.length; i++) { let type = arr[i].code + arr[i].name + arr[i].partNo var n = res.indexOf(type); if (n == -1) { res.push(arr[i].code + arr[i].name + arr[i].partNo); narr.push({ "name": arr[i].code, fraction: [arr[i]] }) } else { narr[n].fraction.push(arr[i]) } } let mag = [] for(var i =0;i<narr.length;i++){ let uid = generateUUID() let new_arry = narr[i].fraction for(var k=0;k<new_arry.length;k++){ new_arry[k].CnNum = uid mag.push(new_arry[k]) } } console.log('添加ID',narr) console.log('新数组ID',mag) ```