Underscore.js is a powerful JavaScript library that provides useful functional programming helpers. Why useful? Let see in a couple of examples below but in a few words it allows you to make your code more clear and compact.
First example is filtering of the list. Let say you have trivial list of
integer numbers and need to find even ones. I am sure every developer
knows how to do it using for
loop:
Compare it with implementation using Underscore’s filter
function:
Second example is optimization of the search performed on some list. In some situation when you need to repeat array search in a cycle it make sense to convert it into hash map. Let’s say you have a list of integer numbers and you do as usual:
See how it’s trivial with indexBy
function:
So if you want to write less code to achive result, then Underscore.js is your friend :-) See Underscore.js web site and learn new useful tricks. Another good source of documentation for Undescore and many other libraries is DevDocs