Underscore js in Node Js

Posted By :Rakesh Chandra |27th February 2020


 What is underscore.js and how to use underscore.js in Node.js?


 underscore.js is a javascript library that provides us a helper function for manipulating an object without extending its core object.
 underscore.js allow us to write cleaner code which is easy for another developer to  read and understand. 
 underscore.js is written by Jeremy Ashkens  . underscore .js is an open-source library . underscore collection is denoted by ( _. ).

 

  Collection function in underscore.js?


 collection function are those function that works on array , Objects or nodelist .underscore allows us to use numbers of a collection in your nodelist , object  , array .  following are some underscore.js collection - 

Function name     Prototype


each         :  _.each(list, iteratee, [context])


map          :  _.map(list, iteratee, [context])


find          :  _.find(list, predicate, [context])


filter        :  _.filter(list, predicate, [context]) 


reject       : _.reject(list, predicate, [context])

 

 How to use underscore .js in node js ?


   For installing underscore.js in node js you have to install underscore.js library from NPM
   use the following command for installing underscore.js in your node.js project 
   Step1 -  npm install underscore  or npm i underscore.

 

   

  step 2  - include underscore.js library in your existing project by following - const _. = require("underscore.js)

 

  
  


  there are numbers of collections provides by underscore.js List of  some most used collection here  - 
    
    1) Each ( _.each ) -
    2) MAP (_.map )
    3) find(_.find)
    4) filter(_.filter)
    5) toArray_.toArray(list)

 

   example how to use  each collection method is node js  - 

 

     

   Advantages of underscore.js 


    1) underscore .js is an open source libaray .
    2) we can use it with frontend(Angular,React)  and backend(Node js ) both.
    3) There are a number of collections available in underscore.js.
    4)  Clean  and easy to understand code.
    5) Reduce code complexity by using the collection's rather than repetitive code and Algorithm. 
  

 


 Conclusion - 

underscore.js is an open-source library that provides a collection that helps us to work in the actual implementation of the project rather than working on repetitive task or algorithm . its make code cleaner and easy to understand and reduce code complexity.

 

 

Thanks ,


  

 
   

 


About Author

Rakesh Chandra

Rakesh has a good Knowledge of Node js,React js ,Web-Crawling/Scraping, Mysql/NOSql ,mongodb/couchdb ,AWS and GCP.

Request For Proposal

Sending message..

Ready to innovate ? Let's get in touch


Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Notice: Undefined index: HTTP_REFERER in /var/html/www/AI/wp-content/themes/oxides-child/functions.php on line 272

Chat With Us