What is array some in JavaScript
In this article, I am going to explain some method in JavaScript.
Array some method in JavaScript
JavaScript some method checks whether some elements of an array pass the test implemented by the callback function. If it satisfy then it return true otherwise return false.
Syntax of some function
array.some(callback [,thisObject]);
|
Parameters in some method:
-
callback
Callback test for each element.
-
thisObject
thisobject is optional, and it is use as this when executing callback.
Return value of some method
It returns true or false according to condition.
There are the following callback function parameter:
Parameter |
Value |
value |
Value of array element. |
index |
Numeric index of the array element. |
Example of some method
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Array Some Method</title>
</head>
<body>
<script type="text/javascript">
var isNumeric = function(x) {
var RegExp = /^(-)?(\d*)(\.?)(\d*)$/;
return String(x).match(RegExp);
}
var myArray = ['one', 'two', 'three', 'four', 'five'];
document.writeln(myArray.some(isNumeric));
var myArray = ['one', 'two', 3, 'four', 'five'];
document.writeln(myArray.some(isNumeric));
</script>
</body>
</html>
|
Output:
Ask Your Question
Got a programming related question? You may want to post your question here