When we need to perform certain actions like sorting, joining, joining with some symbol, then we can use this underscore function to easily achieve all this actions. The _.invoke() function is used to perform certain actions like sorting, joining, joining with some symbol, make upper case etc the elements of an array. It call the function directly… Continue reading How to perform “Sorting, Joining or joining with some symbol” actions on all array elements by using Underscore.js function _.invoke()
Tag: underscore functions
_.find() in Underscore.js
This is the Undescore.js library function that allows us to iterate over your collection and finding the value in that collection based on the algorithm implemented. Following is the way we can use this function. output [2, 4]
Underscore.JS – invert method
Invert method swaps the key and values of object passed. var result = _.invert({one: 1, two : 2, three: 3}); console.log(result); // Example 2 result = _.invert({ name: ‘Sam’, age: 30}); console.log(result); Output { ‘1’: ‘one’, ‘2’: ‘two’, ‘3’: ‘three’ } { ’30’: ‘age’, Sam: ‘name’ }