index.js 387 B

1234567891011121314151617
  1. export function convertArray(arr) {
  2. let convertedArr = [];
  3. arr.forEach(item => {
  4. let findIndex = convertedArr.findIndex(i => i.gatewayDeviceId === item.gatewayDeviceId);
  5. if (findIndex === -1) {
  6. convertedArr.push({
  7. gatewayDeviceId: item.gatewayDeviceId,
  8. children: [item]
  9. });
  10. } else {
  11. convertedArr[findIndex].children.push(item);
  12. }
  13. });
  14. return convertedArr;
  15. }