Sunday, February 22, 2026
HomeLanguagesJavascriptUnderscore.js _.find() Function

Underscore.js _.find() Function

The _.find() function looks at each element of the list and returns the first occurrence of the element that satisfy the condition. If any element of list is not satisfy the condition then it returns the undefined value.

Syntax:

_.find(list, predicate, [context])

Parameters: This function accept three parameters as mentioned above and described below:

  • list: This parameter is used to hold the list of items.
  • predicate: This parameter is used to hold the truth condition.
  • context: The text content which need to be display. It is an optional parameter.

Return value: It returns the first occurrence of the element that satisfy the condition.

Example 1:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var oddNo = _.find([5, 6, 7, 8, 9, 10],
            function (num) {
                return num % 2 != 0;
            });
        console.log(oddNo); 
    </script>
</body>
  
</html>


Output:

5

Example 2:




<!DOCTYPE html>
<html>
  
<head>
    <script type="text/javascript" src=
    </script>
</head>
  
<body>
    <script type="text/javascript">
        var words = ['javascript', 'java', 'unix',
                     'hypertext', 'underscore', 'CSS'];
  
        const result = words.find(word => word.length == 9);
        console.log(result); 
    </script>
</body>
  
</html>


Output:

hypertext
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS