![]() |
VOOZH | about |
Underscore.js_.some() function is used to find whether any value in the given list matches the given condition or not. If at least one value satisfies this condition then the output will be true. When none of the values matches then the output will be false.
_.some(list, [predicate], [context]);The return value that is either trueThe either true return value (when at least one element of the list fulfills the given condition) or false (when none of the elements fulfill the condition).
The ._some() function takes the elements from the list one by one and then checks the condition by doing the specified operations on the code. The operation is to find whether the array contains any true elements or not.
Example: This example shows passing an array to the _.some() function.
Output:
👁 Image
Example: In the below code since the array contains all false elements like '0', 'false', 'null' and no true elements, so the output will be 'false'.
Output:
👁 ImageFirst, define both list and the function which need to performed/checked on the list. Then pass the list and the function as arguments to the _.some() function. If the condition given in the function is satisfied even by 1 of the element of the list then the output will be true.
Example: This example shows passing a list of numbers and a function _.some() function.
Output:
👁 ImageFirst declare the array (here array is 'people'). Choose one condition on which need to check like here 'longHairs'. Console.log the final answer. Since, three people's 'longHair' property is true so the resultant is also true.
Example: This example shows passing a structure to the _.some() function.
Output:
👁 ImagePassing different objects to each _.some() function and then use the following results together by using the logical operators like '&&', '||', '!' etc. The object1 and arralist1 contains atleast one true value so the resultant of two true will also be true. Hence, first condition is satisfied. The object2 is empty and arraylist2 also is also empty so they are not valid. Since use '!' before every _.some() function so the resultant are 2 true values.
Example: This example shows use of the _.some() function and another custom.
Output:
Example: This example shows use of the _.some() function.