1234567891011121314151617 |
- export function convertArray(arr) {
- let convertedArr = [];
- arr.forEach(item => {
- let findIndex = convertedArr.findIndex(i => i.gatewayDeviceId === item.gatewayDeviceId);
- if (findIndex === -1) {
- convertedArr.push({
- gatewayDeviceId: item.gatewayDeviceId,
- children: [item]
- });
- } else {
- convertedArr[findIndex].children.push(item);
- }
- });
- return convertedArr;
- }
|