我有一個數組:JS:組陣列由值嵌套數組
[
{
theme: "low battery",
Number: "S-10",
components: [ "hardware", "battery" ]
},
{
theme: "bad sync",
Number: "S-11",
components: [ "software" ]
},
{
theme: "misc troubles",
Number: "S-12",
components: [ "hardware", "software" ]
}
]
所以想要組這個數組由「組件」的值。換句話說,我想知道,組件在數組中發生了多少次。例如:
[
{
component: "hardware",
amount: 2
},
{
component: "software",
amount: 2
},
{
component: "battery",
amount: 1
}
]
的可能的複製[什麼是GROUPBY對象的JavaScript的陣列上的最有效的方法?(https://stackoverflow.com/questions/14446511/what-is-the最有效的方法到對象上的一個javascript對象數組) – Andreas