我有一個對象的數組,我需要轉換爲表(一種數據透視)。說到這一點,我需要獲得另一個對象數組,其中包含具有嵌套對象數組的唯一標題以及值對。你可以看看這個,並幫助解決我需要的東西嗎?請參閱原件及以下所需的陣列:如何在JavaScript中旋轉對象數組?
原始數組:
[
{title: "Title1", value1: "value1", value2: "value2"},
{title: "Title2", value1: "value1", value2: "value2"},
{title: "Title1", value1: "value1", value2: "value2"},
{title: "Title3", value1: "value1", value2: "value2"},
{title: "Title2", value1: "value1", value2: "value2"},
{title: "Title1", value1: "value1", value2: "value2"},
{title: "Title3", value1: "value1", value2: "value2"},
{title: "Title1", value1: "value1", value2: "value2"},
]
期望的結果:
[
{title: "Title1", values: [{value1: "value1"}, {value2: "value2"}]},
{title: "Title2", values: [{value1: "value1"}, {value2: "value2"}]},
{title: "Title3", values: [{value1: "value1"}, {value2: "value2"}]},
]
感謝,如果提前的任何建議。
對於您的示例來說,太多重複的「value1」「value2」也無濟於事。 – Paulpro
結果真的是想要的結果? –