Javascript Equivalent to C# LINQ Select

前端 未结 12 1534
孤街浪徒
孤街浪徒 2020-12-02 06:33

Following this question here :

Using the checked binding in knockout with a list of checkboxes checks all the checkboxes

I\'ve c

12条回答
  •  没有蜡笔的小新
    2020-12-02 06:50

    I know it is a late answer but it was useful to me! Just to complete, using the $.grep function you can emulate the linq where().

    Linq:

    var maleNames = people
    .Where(p => p.Sex == "M")
    .Select(p => p.Name)
    

    Javascript:

    // replace where  with $.grep
    //         select with $.map
    var maleNames = $.grep(people, function (p) { return p.Sex == 'M'; })
                .map(function (p) { return p.Name; });
    

提交回复
热议问题