Get Uniqe (specific prop) by array of objects

PHOTO EMBED

Tue Mar 29 2022 06:34:41 GMT+0000 (Coordinated Universal Time)

Saved by @KhaledOghli #javascript

    getDrawingCategoryTypes() {
      const vue = this;
      const buldingFiles = [];
      this?.request?.details?.buildings?.forEach((building, index) => {
        const types = new Set();
        building.buildingFiles?.forEach(category => types.add(category?.typeID));
        const data = Array.from(types).map(typeId => {
          const filterdData = building.buildingFiles?.filter(i => i?.typeID === typeId);
          return {
            typeId: typeId,
            typeName: filterdData[0]?.typeName,
            obj:filterdData[0],
          };
        });
        buldingFiles.push({ data: data, index: index });
      });
      console.log('bFiles',buldingFiles);
      return buldingFiles;
    },
content_copyCOPY

i have 2 building each building has Building Files each one has files i want to get uniqe category by Typeid and type id in files buildings: [ { "name": "xxxxx", "code": "DRFT-20 - 1", "cost": 333.0, "details": { "noOfFloors": null, "noOfLifts": 77, "height": 55.0, "usageArea": null, "builtUpArea": null, "greenBuildingCategoryId": 3, "usageClassificationId": 1, "isPhysical": false, "isUploadManual": true, "usages": [{ "masterUsageId": 7, "mainUsageId": 83, "iD": 2 }], "extraInfo": { "foundationTypeId": 4, "structural": 33, "thermalElectroMechanical": 55, "carParkingBuilding": false, "acUnitTypeId": 3, "airConditionedArea": 7, "drainageConnection": false, "claddingSystem": false, "electricalLoad": 77, "thermalLoad": 6, "windowToWall": 55, "capacityEnergy": 66, "structureSystemScore": 7, "wallSystemScore": 7, "bonusScore": 6, "buildingSystemScore": 6 }, "floors": [ ] }, "buildingFiles": [ { "id": 1, "name": "Architectural Drawings", "code": "ARC", "typeID": 1, "typeName": "Drawing", "allowedFileTypes": ".dwf", "allowedMaxSize": 10, "allowedEChecking": true, "isRequired": true, "files": [ { "type": "Architectural Drawings ", "name": "blocks_and_tables.dwf", "fileCategoryId": 1, "uploadDate": "14/03/2022", "fileSize": 101370, "id": 13 } ], }, { "id": 2, "name": "Interior Drawings", "code": "INT", "typeID": 3, "typeName": "Interior", "allowedFileTypes": ".dwf", "allowedMaxSize": 10, "allowedEChecking": false, "isRequired": false, "files": [ { "type": "Int Drawings 2", "name": "blocks_and_tables123.dwf", "fileCategoryId": 3, "uploadDate": "14/03/2022", "fileSize": 101370, "id": 14 } ], }, ] }, { "name": "777", "code": "DRFT-20 - 2", "cost": 6.0, "details": { "noOfFloors": null, "noOfLifts": 6, "height": 6.0, "usageArea": null, "builtUpArea": null, "greenBuildingCategoryId": 2, "usageClassificationId": 2, "isPhysical": false, "isUploadManual": true, "usages": [{ "masterUsageId": 6, "mainUsageId": 77, "id": 3 }], "extraInfo": { "foundationTypeId": 2, "structural": 55, "thermalElectroMechanical": 555, "carParkingBuilding": false, "acUnitTypeId": 3, "airConditionedArea": 666, "drainageConnection": false, "claddingSystem": false, "electricalLoad": 77, "thermalLoad": 55, "windowToWall": 33, "capacityEnergy": 22, "structureSystemScore": 1, "wallSystemScore": 3, "bonusScore": 4, "buildingSystemScore": 5 }, "floors": [ ] }, "buildingFiles": [ { "name": "Architectural Drawings building2", "code": "ARC", "typeID": 1, "typeName": "Drawing", "allowedFileTypes": ".dwf", "allowedMaxSize": 10, "allowedEChecking": true, "isRequired": true, "files": [ { "type": "Architectural Drawings build2", "name": "blocks_and_tables.dwf", "fileCategoryId": 1, "uploadDate": "14/03/2022", "fileSize": 101370, "id": 13 } ], "id": 1 }, ], } ],