0
我有以下格式的JavaScript對象,我想它歸類歸類數據散列映射
var inputFacetArray=[
{ category:
"Company"
, name:
"nokia"
}, { category:
"Persons"
, name:
"ben affleck"
}, { category:
"Persons"
, name:
"daniel craig"
}, { category:
"Persons"
, name:
"george clooney"
}]
我想獲得它的輸出格式
[{Persons:["george clooney", "daniel craig", "ben affleck"]}, {company:["nokia"]}]
我的代碼如下
var facetCategorizedArray=[];
for(var k=0; k<inputFacetArray.length; k++){
var l={};
inputFacetArray[k]["name"].push(l[inputFacetArray[k].category]);
facetCategorizedArray.push(l);
}
上面的代碼無法正常工作。