"Underscore.js" a tiny and powerful library with a minified size of 5.7kb. You can download this library from
http://underscorejs.org/underscore-min.js
This library support over hundred of functions which can be very useful in our day to day JavaScript work.
The whole information about the "Underscore.js" can be found over the link below :-
http://underscorejs.org/
It can perform the operations such as finding index, unique elements, set operations like union, intersection, difference etc.
Below is some of the samples with output :-
//I have used two arrays
// To get all list of functions just put underscore(_) and dot(.) after it like(_.)
var stringarray = ["a", "b", "a", "b", "c", "d"];
var numberarray = [1, 2, 3, 4, 5, 6];
console.log(_.first(stringarray, 2));
console.log( _.lastIndexOf(numberarray, 3));
console.log(_.difference([2, 30, 40], [1, 2, 3]));
console.log(_.uniq(stringarray));
//Sorting by person age.
var people = [{ name: 'TestName1', age: 50 }, { name: 'TestName2', age: 30 }];
console.log('Given Object:' + JSON.stringify(people))
people = _.sortBy(people, function (person) { return person.age; });
console.log('Result:' + JSON.stringify(people));
OutPut:-
["a", "b"]
2
[30, 40]
["a", "b", "c", "d"]
Given Object:[{"name":"TestName1","age":50},{"name":"TestName2","age":30}]
Result:[{"name":"TestName2","age":30},{"name":"TestName1","age":50}]
Before thinking about complex logic in jquery developers can think about this library.
Reference :- http://underscorejs.org/
0 Comment(s)