The some method in JavaScript assesses the elements of an array to determine whether they meet a specified condition. This condition is evaluated using a function provided as an argument.
Syntax:
Example
array.some(function(value, index, arr), thisValue)
Parameters:
Array: The array on which the some method is invoked.
Index: the position of the current value that the method is handling.
Value : The value of the current element.
ThisValue: The parameter that will be assigned to the method as the context value.
Return value:
It yields a true value if the elements within the array meet the specified condition. Conversely, if the elements do not fulfill the condition, it returns false.
Browser Support:
| Chrome | Yes |
|---|---|
| Safari | Yes |
| Firefox | Yes |
| Opera | Yes |
Example 1
JavaScript TypedArray some Method.
Example
<script>
// JavaScript to illustrate some() method
function Example(element, index, array)
{
return element > 5;
}
function isMore()
{
// array
var array = [1,2,3,4,5,6,7,8,9];
// Checking for condition in array
var value = array.some(checkFunction);
document.write(value);
// expected output: arr[Output: True]
}
isMore();
</script>
Output:
Example 2
JavaScript TypedArray some Method.
Example
<script>
// JavaScript to illustrate some() method
function Example(element, index, array)
{
return element > 5;
}
function isMore()
{
// Original array
var array = [1,2,3,4];
// checking for condition in array
var value = array.some(checkFunction);
document.write(value);
// expected output: arr[Output:false]
}
isMore();
</script>
Output: