代码如下:
let tempArr = [];
let Data = [];
for (let i = 0; i < resData.length; i++)
{ if (tempArr.indexOf(resData[i].tagName) === -1) {
Data.push({ tagName: resData[i].tagName, dataInfo: [resData[i]] }); tempArr.push(resData[i].tagName);
} else { for (let j = 0; j < Data.length; j++) {
if (Data[j].tagName == resData[i].tagName)
{ Data[j].dataInfo.push(resData[i]); break; } } } }
console.log(Data);
摘抄自:https://blog.csdn.net/m0_45833941/article/details/103820257