Javascript Some() Function

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])

Javascript Some() Function Example1

<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

Javascript Some() Function Example2

<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

Javascript Some Method Example3

<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