score:2
Disclaimer: I wrote this library
You could use the javascript loq library to achieve this. Here's a snippet to get you on your way:
var list = [
{name:"dog",type:"animal"},
{name:"cat",type:"animal"},
{name:"snake",type:"animal"},
{name:"table",type:"furniture"},
{name:"chair",type:"furniture"},
];
var filtered = loq(list).distinctBy(item => item.type);
console.log(filtered.toArray());
<script src="https://cdn.rawgit.com/biggyspender/loq/67db7014/lib/loq.min.js"></script>
...or with requirejs
requirejs.config({
paths: {
loq: 'https://cdn.rawgit.com/biggyspender/loq/67db7014/lib/loq.min'
}
});
require(['loq'], function(loq){
var list = [
{name:"dog",type:"animal"},
{name:"cat",type:"animal"},
{name:"snake",type:"animal"},
{name:"table",type:"furniture"},
{name:"chair",type:"furniture"},
];
var filtered = loq(list).distinctBy(item => item.type);
console.log(filtered.toArray());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.1.14/require.js"></script>
It's a relatively complete reimplementation of LINQ-to-objects on iterables (objects that implement Symbol.iterator
) with a few extra goodies (such as distinctBy
). Take a look at the tests to see other uses.
Source: stackoverflow.com
Related Articles
- Lodash Equivalent to C# LINQ GroupBy and Select in TypeScript
- Code equivalent to the 'let' keyword in chained LINQ extension method calls
- Linq code to select one item
- How to select top N rows in a Linq GroupBy
- How to select last record in a LINQ GroupBy clause
- LINQ Source Code Available
- Dynamic Linq Groupby SELECT Key, List<T>
- How to render this map-reduce javascript code to an equivalent LINQ Select-Aggregate?
- LINQ Lambda efficiency of code groupby orderby
- LINQ Select on GroupBy in MongoDB C# driver 2.1
- creating Linq to sqlite dbml from DbLinq source code
- LINQ GroupBy and Select on different property
- Avoiding duplicate code in Linq Select method
- LINQ GroupBy Select only where key is not null
- C # Linq SelectMany, TypeScript Equivalent
- Linq Min in Select new & Multiple GroupBy columns
- Range projection: equivalent of LINQ select in D?
- Linq equivalent for grouping select
- Dynamic Linq GroupBy Select not working properly
- Dynamic Linq select first in groups after GroupBy
- Linq union all equivalent of sql code
- C# code for equivalent LINQ query
- Encapsulate LINQ GroupBy Select
- What is the equivalent T-SQL select query for the attached linq query?
- How to Select top (5) contributors group by Business type code in c# linq query
- Ruby Sequel Equivalent to LINQ to SQL select anonymous objects
- LINQ Equivalent of SELECT DISTINCT
- Using Linq to GroupBy and Select
- how to write LINQ to objects equivalent code for this code
- LINQ GroupBy - Select lowest ID group by name
- Working with the data from LinQ SQL query
- Bind linq data to dropdownlist
- linq error Defined default value for hashset
- How to deal with dates in Linq Query?
- Modify list of strings to only have max n-length strings (use of Linq)
- Linq "Where In" subquery to filter data
- Linq Loop Through Columns in Row C#
- Compact way to map an IEnumerable to an ILookup with LINQ
- Intermittent error Linq to NHibernate Sequence Contains no Elements
- Trim string in LINQ C#
- LINQ remove overlaps of datetime that are common in 2 lists
- How can I get the highest number in this Linq result?
- return list from linq function
- Query update multiple rows
- How to restrict LINQ query to marketing lists of a given campaign?
- LINQ to Entities does not recognize the method
- DisplayMemberPath and SelectedValuePath issue while using LINQ to generate ComboBox.ItemsSource
- Can I put a list of a reference object in the KeySelector in a GroupBy?
- listbox troubles. I have no idea
- Linq Scope Problem + Reduce Repeated Code