How to use Underscore JS in Node JS App?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

Hello Brother, i will show you node js underscore lesson. We will use underscore js sort array of objects node js. i explained simply about underscore js in node js. Here you will learn how to use underscore js in node js.

Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. underscore js provide lots of array objects helper function that way you can easily work with array. it provides helper function like sortBy, each, map, find, filter, max, min, groupBy etc.

i given very simple lesson bellow:

Example:

Install Underscore:

npm install underscore

server.js

var _ = require('underscore');

objs = [

{ name:'Paresh', age: 32, email: 'paresh@gmail.com'},

{ name:'Sagor', age: 30, email: 'hardik@gmail.com'},

{ name:'Ankit', age: 60, email: 'ankit@gmail.com'},

];

var newObjName = _.sortBy(objs, 'name');

console.log(newObjName);

var newObjAge = _.sortBy(objs, 'age');

console.log(newObjAge);

Result:-

[

{ name: 'Ankit', age: 60, email: 'ankit@gmail.com' },

{ name: 'Sagor', age: 30, email: 'hardik@gmail.com' },

{ name: 'Paresh', age: 32, email: 'paresh@gmail.com' }

]

[

{ name: 'Sagor', age: 30, email: 'hardik@gmail.com' },

{ name: 'Paresh', age: 32, email: 'paresh@gmail.com' },

{ name: 'Ankit', age: 60, email: 'ankit@gmail.com' }

]

thank you very much for following up with me.

Tags

Recent Posts

Related Posts