我有这个数组:
var arr = [{
"gid": "affected_bxu_nrt.1",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.2",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.3",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
},
...
我已设法删除重复的对象,但如何计算重复项的出现次数?
这个想法是,如果数组中的对象是相同的,请计算它。输出应该为每个对象添加count
属性,并且count
属性的值应该是它的出现。
const result = {
data: arr
}
result.data = result.data.filter((result, index, self) =>
index === self.findIndex((t) => (t.bldg_name === result.bldg_name && t.psa_brgy === result.psa_brgy && t.bldg_type === result.bldg_type && t.hazard_level === result.hazard_level)
)
)
console.log(result)
答案 0 :(得分:0)
您可以在这里找到解决方案。
var arr = [{
"gid": "affected_bxu_nrt.1",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.2",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.3",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.4",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.5",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.6",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.7",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.8",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.9",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.10",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.11",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.12",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.13",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.14",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.15",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.16",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.17",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.18",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.19",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.20",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.21",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.22",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.23",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.24",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.25",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.26",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.27",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.28",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.29",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.30",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.31",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.32",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.33",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.34",
"bldg_name": "Unknown",
"psa_brgy": "Obrero Pob. (Bgy. 18)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.35",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.36",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.37",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.38",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.39",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.40",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.41",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.42",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.43",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.44",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.45",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.46",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.47",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.48",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.49",
"bldg_name": "San Miguel",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Factory",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.50",
"bldg_name": "Unknown",
"psa_brgy": "Port Poyohon Pob. (Bgy. 17 - New Asia)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.51",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.52",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.53",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.54",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.55",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.56",
"bldg_name": "Unknown",
"psa_brgy": "Ong Yiu Pob. (Bgy. 16)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.57",
"bldg_name": "Unknown",
"psa_brgy": "Leon Kilat Pob. (Bgy. 13)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.58",
"bldg_name": "Unknown",
"psa_brgy": "Leon Kilat Pob. (Bgy. 13)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.59",
"bldg_name": "Unknown",
"psa_brgy": "Leon Kilat Pob. (Bgy. 13)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.60",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.61",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.62",
"bldg_name": "Unknown",
"psa_brgy": "Doongan",
"bldg_type": "Residential",
"hazard_level": "LOW"
}, {
"gid": "affected_bxu_nrt.63",
"bldg_name": "Unknown",
"psa_brgy": "Bading Pob. (Bgy. 22)",
"bldg_type": "Residential",
"hazard_level": "LOW"
}, {
"gid": "affected_bxu_nrt.64",
"bldg_name": "Unknown",
"psa_brgy": "Doongan",
"bldg_type": "Residential",
"hazard_level": "LOW"
}, {
"gid": "affected_bxu_nrt.65",
"bldg_name": "Unknown",
"psa_brgy": "Doongan",
"bldg_type": "Residential",
"hazard_level": "LOW"
}, {
"gid": "affected_bxu_nrt.66",
"bldg_name": "Unknown",
"psa_brgy": "Doongan",
"bldg_type": "Residential",
"hazard_level": "LOW"
}, {
"gid": "affected_bxu_nrt.67",
"bldg_name": "Unknown",
"psa_brgy": "Agao Pob. (Bgy. 3)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.68",
"bldg_name": "Unknown",
"psa_brgy": "Agao Pob. (Bgy. 3)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.69",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.70",
"bldg_name": "Unknown",
"psa_brgy": "Agao Pob. (Bgy. 3)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.71",
"bldg_name": "Unknown",
"psa_brgy": "Agao Pob. (Bgy. 3)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.72",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.73",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.74",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.75",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.76",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.77",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.78",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.79",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.80",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.81",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.82",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.83",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.84",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.85",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.86",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.87",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.88",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.89",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.90",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.91",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.92",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.93",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.94",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.95",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.96",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.97",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "MEDIUM"
}, {
"gid": "affected_bxu_nrt.98",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.99",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.100",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.101",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.102",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.103",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.104",
"bldg_name": "Unknown",
"psa_brgy": "Golden Ribbon Pob. (Bgy. 2)",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.105",
"bldg_name": "Unknown",
"psa_brgy": "San Vicente",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.106",
"bldg_name": "Unknown",
"psa_brgy": "San Vicente",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}, {
"gid": "affected_bxu_nrt.107",
"bldg_name": "Unknown",
"psa_brgy": "San Vicente",
"bldg_type": "Residential",
"hazard_level": "HIGH"
}];
const result = {
data: arr
}
function compare(obj1, obj2) {
let equal = false;
Object.keys(obj1).every((e) => {
if (e === 'gid' || e === 'count') { return true; }
equal = obj1[e] === obj2[e];
return equal;
});
return equal;
}
const r = arr.reduce(function (rv, x) {
let el = rv.find(function (e) {
if (compare(e, x)) { return e; }
});
if (el) {
if (el.count) { el.count++; }
else { el.count = 1; }
} else {
rv.push(x);
}
return rv;
}, []);
console.log(r)