The _.best() method takes an array and a function and generates the best suitable value from that array using the conditions of the function.
Parameters: This method accepts two parameters as mentioned above and described below:
- array: The given array from which the best value is calculated.
- function: The function which contains the condition for the best matching value.
Return Value: This method returns the best value from the array.
underscore.js contrib library can be installed using npm install underscore-contrib .
Example 1: In this example, we will get the best value as the greatest value from the array.
Array : [ 11, 2, 43, 14, 12 ] Best value : 43
Example 2: In this example, we will get the best value as the smallest value from the array.
Array : [ 11, 2, 43, 14, 12 ] Best value : 2
Example 3: In this example, we will get the best matching value as 12 from the array.
Array : [ 11, 2, 43, 14, 12 ] Best value : 12
- Lodash _.best() Method
- Best way to initialize empty array in PHP
- 6 Best CSS frameworks You should Know to design Attractive Websites
- What is the best way to include CSS file? Why use @import?
- Best way to make a d3.js visualization layout responsive
- What’s the best way to reload / refresh an iframe?
- Best Books to Learn Front-End Web Development
- Best Books to Learn Back-End Web Development
- Programming For Beginners: 10 Best HTML Coding Practices You Must Know
- 7 Best Sites For Free Web Hosting
- Best Security Practices in Node.js
- Best Adobe Software In The Market For UI/UX Designers
- Best approach for “Keep Me Logged In” using PHP
- What are the best input sanitizing functions in PHP ?
- 10 Best Visual Studio Code Extensions to Make Developer's Life Easier
- Best Way to Learn NodeJS - A Complete Roadmap
- How to create the best Google My Business Posts ?
- Difference between Class.method and Class.prototype.method
- Lodash _.method() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.