javascriptlinq.js

Linq js group by Sum appending string instead of adding


I am using linq.js "//cdnjs.cloudflare.com/ajax/libs/linq.js/2.2.0.2/linq.min.js"

The objective is to get "sum" of a field using group by clause. The code is working fine but "quantity" is considered as a string and appending numbers. If I use g.Sum(parseInt("$.quantity")) or parseFloat I am getting error b is not a function. What am I missing?


Solution

  • I figured it out. g.Sum(function (s) { return parseFloat(s.quantity | 0); })