2017-10-18 46 views
0

我有一個動態的鍵值對。angularjs:動態鍵:值對作爲函數的參數

myObj = { 
    category1: ["a","b","c"], 
    category2: ["a","d","e"], 
    category3: ["a","f","g"], 
    ... 
    .. 
    . 
} 

我需要得到交點值爲「a」。對於我使用下劃線的js的 _.intersection()功能

根據動態類,我需要動態參數傳遞給_.intersection()

_.intersection(myObj[category1], myObj[category2], ..., ..., myObj[categoryN]); 

回答

3

嘗試:

_.intersection.apply(_, Object.values(myObj)); 
+0

謝謝! @bluehipy它正在工作 - upvote! –