Latest Code Tutorials

JavaScript array some: How to Check Array Element in JavaScript

Javascript array some() function tests whether some item in the array passes the test implemented by the provided function. The some() method is the JavaScript extension to the ECMA-262 standard; thus, it may not be present in other implementations of the standard.

JavaScript array.some()

JavaScript array some() is a built-in method that checks whether at least one item in the array passes the test implemented by a provided function. It returns the Boolean value.

The some() method in JavaScript executes the function once for each element present in the array:

  1. If it finds an array element where the function returns a true value, then some() function returns true (and it does not check the remaining values).
  2. Otherwise, it returns false.

To check an array element in JavaScript, use the array.some() function.


array.some(function(currentValue, index, arr), thisValue)


JavaScript some() function takes the first parameter as a function that takes the following parameters.

  1. currentValue: It is Required. The value of the current element.
  2. index: It is Optional. The array index of the current element.
  3. arr: It is Optional. The array object the current element belongs to.

The function is the required parameter.

It takes thisValue as a second parameter, which is optional. It is the value to be passed to the function to be used as its “this” value. If the thisValue parameter is empty, the value “undefined” will be given as its “this” value.

Return Value

Javascript some() method returns true if the callback function returns a truthy value for at least one element in the array. Otherwise, it returns false.


Write the following code inside the new file. Let’s call it the app.js file.

// app.js

let dark = [

console.log(dark.some(x => x > 90));



In this example, we defined an array and then checked if the array contains a single item that satisfies the condition, and if it does, then returns true otherwise, it returns false.

The some() function executes the callback function once for each item present in the array until it finds the one where the callback returns the truthy value (a value that becomes true when converted to a Boolean).

If such an item is found, the some() method immediately returns true. Otherwise, it returns false.

The callback is invoked only for indexes of an array with assigned values. It is not invoked for indexes that have been deleted or which have never been assigned values.

The callback is invoked with three arguments: 

  1. The value of the item,
  2. The index of the item,
  3. The Array object is being traversed.

If the thisArg parameter is provided to some() function, it will be used as callback’s this value. Otherwise, the value undefined will be used as this value.

This value ultimately observable by callback is defined according to the usual rules for determining this seen by a function.

The some() function does not mutate the array on which it is called.

The range of elements processed by the some() method is set before the first invocation of callback.

The callback will not visit items appended to the array after the call to some() begins.

If the existing, unvisited item of the array is changed by callback, its value passed to a visiting callback will be the value when some() visits that item’s index. Items that are deleted are not visited.

Checking whether the value exists in an array

Use the array to check if the specified value is present in the array.some() function. Let’s see how to do that.

// app.js

const horcruxes = ['diary', 'ring', 'locket', 'nagini', 'harry'];

function remainingHorcruxes(arr, val) {
  return arr.some(function (arrVal) {
    return val === arrVal;

console.log(remainingHorcruxes(horcruxes, 'harry'));
console.log(remainingHorcruxes(horcruxes, 'diadem'));



In this example, we have defined an array, then defined a function that checks if the passed value exists in the given array. If it exists, then it will return true otherwise returns false.

Check if an array has one element that is in the range

To check if any number in the array is in the range, use the array.some() method.

// app.js

let data = [11, 18, 19, 21, 29];

const range = {
  min: 10,
  max: 30

let result = data.some(function (e) {
  return e >= this.min && e <= this.max;
}, range);




In this example, we check each element against the min and max numbers. If it satisfies the condition, then it returns true otherwise false.

First, we defined a range object with min and max properties.

Second, call the some() function on the marks array object and pass the callback and range object. Because we pass a range object as the second argument (thisArg), we can reference it inside the callback via this value.

Supported Browser

The browsers supported by JavaScript Array some() method are listed below:

  1. Google Chrome
  2. Mozilla Firefox
  3. Internet Explorer
  4. Opera
  5. Safari

That is it for the Javascript array some() method.

See also

JavaScript array includes()

JavaScript array indexOf()

JavaScript array contains

JavaScript array find()

JavaScript array findIndex()

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.