Single Page App – Finding Items in JSON Using Underscore or LoDash
Underscore is a utility-belt library for JavaScript that provides a lot of the functions and programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
Underscore provides 80-odd functions that help you deal with collections, arrays, functions, objects, and more.
You will want Underscore for you non-DOM code or even complex front end code, such as MVC. You can use map, select, invoke or specialized helpers: function binding, JavaScript templating, deep equality testing. Underscore uses built-in functions in modern browsers when you want to use forEach, map, reduce, filter, every, some and indexOf.
Underscore gives you simple templating, too, similar to what you learned about in Object JavaScript – External Templates Using Mustache, jQuery.
You can use Underscore in your Web application or on Node.js.
When minified and GZipped it weighs in at less than 4Kb. Where possible it delegates functionality to native browser implementations for performance. It has no other dependencies and so adds very little overhead to your total script assets. It can be used on the client or server.
In this post, you’ll learn how to use Underscore for finding items in your single page app. You’ll learn how to:
- Select a group of toys based on price cutoff.
- Find a toy from its name.
- Get a sorted list of unique categories.
- Sort the list of product names.
In a later post, you’ll learn how to create a list of search terms and respond to a search request using JavaScript and Underscore.
Continue reading “Single Page App – Finding Items in JSON Using Underscore or LoDash”