The some() function of array object returns true if at least one element in this array satisfies the provided testing function. Use it for example to check element exist in the array.
Syntax
arr.some(callbackfn[, thisArg])
<html>
<head>
<script type="text/javascript">
// Create an array.
var arr = [0, 1, 2, 3, 4, 5];
function equalValue(element, index, array) {
return element == 3;
}
var newArray = arr.some(equalValue);
document.write(newArray);
</script>
</head>
<body>
</body>
</html>
This will produce following result
true
<html>
<head>
<script type="text/javascript">
// Create an array.
var arr = [0, 1, 2, 3, 4, 5];
function equalValue(element, index, array) {
return element == 31;
}
var newArray = arr.some(equalValue);
document.write(newArray);
</script>
</head>
<body>
</body>
</html>
This will produce following result
false
<html>
<head>
<script type="text/javascript">
// Create an array.
var arr = [0, 1, 2, 3, 4, 5];
function equalValue(element, index, array) {
return value < this.minimum || value > this.maximum;
}
// Set range object.
var range = { minimum: 0, maximum: 5 };
var newArray = arr.some(equalValue,range);
document.write(newArray);
</script>
</head>
<body>
</body>
</html>
This will produce following result
true