I am writing some code for a web app that regularly needs to filter down an array of javascript objects to return a subset of objects. I find that throughout my code I end up with numerous for loops. I am planning to write a prototype function that can return a filtered subset using a passed in function, similar to C#’s LINQ lambda or Scala’s filter but I can’t help but think this has already been done, either in the core language or in an external library and I am reinventing the wheel.
Is there a preferred way to functionally return a filtered subset of Json objects without for loops littered through my code. Syntax not being relevant, but a construct and concept similar to:
var filteredObj = obj.filter(function() {... filter function ...});
Have you looked at underscore?
There are a ton of functional programming tools including a
map,filterandreduceThere’s a ton of awesome utility in that library which makes JavaScript a little more, er, ahem, functional.