访问由groupBy返回的Array元素

时间:2019-01-13 10:05:35

标签: javascript ajax laravel web

我已经使用groupBy子句根据日期对JSON数据进行分组-

这是我的输出-

{30-12-2018: Array(1), 12-01-2019: Array(2)}
  12-01-2019: Array(2)
    0: {representativeid: 21, doctor_name: "Test", products: "Sinarest,Globate -G", quantity: "1,2", Retailername: "Kripa Medicals,Nagashree Medicals", …}
    1: {representativeid: 21, doctor_name: "Pass", products: "Sinarest,Globate -G,Mankind", quantity: "1,2,3", Retailername: "Test Retailer", …}
length: 2
__proto__: Array(0)

30-12-2018: Array(1)
   0: {representativeid: 21, doctor_name: "Test", products: "Sinarest,Globate -G", quantity: "1,2", Retailername: "Test Retailer,Nagashree Medicals,Kapila,Kripa Medicals", …}
length: 1
__proto__: Array(0)
__proto__: Object

我想访问每个日期的数据(按事例分别为12日和13日),并希望找到特定日期的代表和医生人数。

groupBy的代码-

var grouped1 = _.mapValues(_.groupBy(data, 'date'),clist => 
clist.map(DataBasedonDate => _.omit(DataBasedonDate, 'date')));
                        console.log(grouped1);

还尝试将数组字符串化为JSON,这是输出-

{"12-01-2019":[{"date":"12-01-2019","representativeid":21,"doctor_name":"Test","products":"Sinarest,Globate -G","quantity":"1,2","Retailername":"Kripa Medicals,Nagashree Medicals","Pob":"10,10","locations":"12.9196032,77.6085504","area":"Sirsi"},{"date":"12-01-2019","representativeid":21,"doctor_name":"Pass","products":"Sinarest,Globate -G,Mankind","quantity":"1,2,3","Retailername":"Test Retailer","Pob":"100","locations":"12.9196032,77.6085504","area":"Sirsi"}]}

任何帮助都会感激

0 个答案:

没有答案