Black lives matter
Portrait Dr. Axel Rauschmayer
Dr. Axel Rauschmayer
Homepage | Twitter
Cover of book “JavaScript for impatient programmers”
Book, exercises, quizzes
(free to read online)
Cover of book “Deep JavaScript”
Book (50% free online)
Cover of book “Tackling TypeScript”
Book (first part free online)
Logo of newsletter “ news”
Newsletter (free)

Trying out Underscore on Node.js

(Ad, please don’t block)

Underscore is a library that nicely rounds out JavaScript’s rather limited standard library. Thanks to the Node Package Manager, it’s very simple to install on Node.js:

    $ npm install underscore
Then you can use it in code as follows:
    var _ = require("underscore");
If you want to play with Underscore interactively in the Node.js REPL, you can’t give it the name _, because that is used by the REPL, to hold the previous input:
    > 3 + 4
    > _
Solution: choose another name.
    > var u = require("underscore");
    > u.uniq([5, 3, 5, 5, 3, 1])
    [ 5, 3, 1 ]