Raza Raza - 1 year ago 731
Javascript Question

linq.js groupby with Json

This is my Json Object in simplified form.

var jsonObject =

I want to groupBy using City and get the count of records belonging to a specific city, The code that I've tried so far is

var query2 = $.Enumerable.From(jsonObject)
function(record) {return record.City},

function(record) {
return {City: record.City}
function(rec) {
return {City:rec}

I'm still not able to get what i'm doing wrong here. i'm new to linq.js...any help would be appretiated, or atleast point me at right direction.

Answer Source

//group the records

                                    "{ City: $.City }",
                                    function (key, g) {
                                        var result = {
                                        var groupResults = [];
                                        g.ForEach(function (item) {

                                    //push into array
                                "$.City" // compare selector needed

This solved my problem.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download