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]
Tag: underscorejs
Underscore.JS – values method
Syntax_.values(object) values method return all the values of object’s properties. // Example 1 var result = _.values({one: 1, two : 2, three: 3}); console.log(result); Output [ 1, 2, 3 ]
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’ }