📜  js json groupby prop - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:22.844000             🧑  作者: Mango

代码示例2
var myJsonFromSQL = [{id:1, cat:'test1'},{id:2, cat:'test1'},
                     {id:3, cat:'test2'},{id:4, cat:'test2'}];

// 1 LINE CODE:
//'Set' deletes/do not consider duplicates
const arr_cat =  [...new Set(myJsonFromSQL.map(i => i.cat))];
//RESULT:
You will get an array with the property values grouped:
arr_cat   ['test1','test2']