Questions tagged [underscore.js]

Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It's the tie to go along with jQuery's tux.

Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It's the tie to go along with jQuery's tux and Backbone.js's suspenders.

Underscore provides 80-odd functions that support both the usual functional suspects: map, select, invoke — as well as more specialized helpers: function binding, JavaScript templating, deep equality testing and so on. It delegates to built-in functions, if present, so that modern browsers will use the native implementations of forEach, map, reduce, filter, every, some and indexOf.


Useful links:

5699 questions
1657
votes
12 answers

Differences between Lodash and Underscore.js

Why would someone prefer either the Lodash or Underscore.js utility library over the other? Lodash seems to be a drop-in replacement for underscore, the latter having been around longer. I think both are brilliant, but I do not know enough about how…
Brian M. Hunt
  • 71,376
  • 65
  • 208
  • 328
635
votes
52 answers

Most efficient method to groupby on an array of objects

What is the most efficient way to groupby objects in an array? For example, given this array of objects: [ { Phase: "Phase 1", Step: "Step 1", Task: "Task 1", Value: "5" }, { Phase: "Phase 1", Step: "Step 1", Task: "Task 2", Value: "10" }, …
D'Arcy Rail-Ip
  • 8,635
  • 9
  • 35
  • 60
468
votes
7 answers

Explanation of

I just stumbled upon something I've never seen before. In the source of Backbone.js's example TODO application (Backbone TODO Example) they had their templates inside a , which contained code that looks like…
Matt
  • 19,783
  • 24
  • 71
  • 113
270
votes
15 answers

Serialize form data to JSON

I want to do some pre-server-validation of a form in a Backbone.js model. To do this I need to get the user input from a form into usable data. I found three methods to do this: var input = $("#inputId").val(); var input =…
dev.pus
  • 7,047
  • 12
  • 34
  • 49
267
votes
8 answers

How to use underscore.js as a template engine?

I'm trying to learn about new usages of javascript as a serverside language and as a functional language. Few days ago I heard about node.js and express framework. Then I saw about underscore.js as a set of utility functions. I saw this question on…
243
votes
8 answers

How to use if statements in underscore.js templates?

I'm using the underscore.js templating function and have done a template like this: