some takes in a callback function where you can write your own logic to determine if an array contains some element which matches the conditions you wrote.

includes does a generic equalTo comparison on every element and will return true if at least one element in the array is equal to the value to find.

Answer from RecursiveThinking on Stack Overflow
🌐
Medium
d7k.medium.com › js-includes-vs-some-b3cd546a7bc3
JS .includes() vs .some()
November 20, 2019 - The method .includes()returns true only if the element exists inside the array. Much leaner, yeah?
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › some
Array.prototype.some() - JavaScript | MDN
The some() method of Array instances returns true if it finds an element in the array that satisfies the provided testing function. Otherwise, it returns false.
🌐
DEV Community
dev.to › caused › comment › k28g
The only difference between some() and includes() is the parameter (the forme... - DEV Community
The only difference between some() and includes() is the parameter (the former is a function, the latter an element) or Did I miss something? ... Yes, they are kinda similar. They both check if a given element exists in the array or not.
🌐
Reddit
reddit.com › r/learnjavascript › what is the correct situation to use array.find() vs. array.includes vs. array.some() ?
r/learnjavascript on Reddit: What is the correct situation to use array.find() vs. array.includes vs. array.some() ?
September 14, 2019 -

I understand how each of these methods work, but they all seem to have similar functions to one another, and I'm not sure as to what situation might call for what method.

🌐
Quora
quora.com › What-is-the-correct-situation-to-use-array-find-vs-array-includes-vs-array-some-in-JavaScript
What is the correct situation to use array.find() vs. array.includes vs. array.some() in JavaScript? - Quora
Answer (1 of 2): includes: this is syntactic sugar for the old common way of writing [code]myArray.indexOf('some value') !== -1 [/code]Which can now be written as [code]myArray.includes('some value') [/code]It simply checks to see if some value exists in the array and returns true if it does. ...
🌐
YouTube
youtube.com › shorts › V9hmv9NiAxw
Includes VS Some In JavaScript #javascript #javascripttutorial #javascriptlearning #webdevelopment - YouTube
June 21, 2024 - The difference between the includes and some array functions in JavaScript.⭐ Get my full-stack Next.js with Express & TypeScript course: https://codinginflow...
Find elsewhere
🌐
MeasureThat
measurethat.net › Benchmarks › Show › 8221 › 0 › array-indexof-vs-includes-vs-some
Benchmark: array indexOf vs includes vs some - MeasureThat.net
array indexOf vs includes vs some aaa · array indexOf vs includes vs some 4 elements · find vs includes vs indexof · array indexOf vs includes vs some vs for loop · Comments · Do you really want to delete benchmark?
🌐
Towards Data Science
towardsdatascience.com › home › latest › should you use .includes or .filter to check if an array contains an item?
Should You Use .includes or .filter to Check if An Array Contains an Item? | Towards Data Science
March 5, 2025 - Depending on your project, you might find that .filter() is a better tool than .includes() – and you might also consider using .some() or .find(). Each one serves a slightly different purpose, but it’s good to keep in mind that there will likely be performance differences. You should absolutely use .includes()… unless you are working with an array of hundreds of thousands of items, in which case you should definitely use a for loop to improve performance!
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Includes vs. In
August 18, 2022 - Today I ran into some trouble with a line of code that seems to be misleading. I tried to use if (!(arr[n][i] in arr[0])){ but I found I had to rewrite the code as if (!(result.includes(arr[n][i]))){ I am having dif…
🌐
Cangaceirojavascript
cangaceirojavascript.com.br › array-includes-vs-array-some
Array.includes vs Array.some
January 8, 2018 - Neste artigo veremos as funções Array.includes e Array.some, inclusive pegadinhas e quando aplicar uma ou outra.
🌐
DEV Community
dev.to › arnaud › using-array-prototype-includes-vs-set-prototype-has-to-filter-arrays-41fg
Using Array.prototype.includes() vs Set.prototype.has() to filter arrays - DEV Community
July 2, 2020 - Length of values to keep: 1 Length of values to test: 10 includes: 0.207ms has: 0.190ms Length of values to keep: 10 Length of values to test: 100 includes: 0.020ms has: 0.017ms Length of values to keep: 100 Length of values to test: 1000 includes: 0.204ms has: 0.071ms Length of values to keep: 1000 Length of values to test: 10000 includes: 9.942ms has: 1.307ms Length of values to keep: 10000 Length of values to test: 100000 includes: 131.686ms has: 8.016ms Length of values to keep: 100000 Length of values to test: 1000000 includes: 1324.318ms has: 71.495ms · So yes, I am right that with a small quantity of data, Array.includes and Set.has perform roughly the same, but we can see how quickly performance degrades, and the change is so small that it's hard to justify not making it, even for small data samples.
Top answer
1 of 11
207

tl;dr: NaN is treated differently:

  • [NaN].indexOf(NaN) > -1 is false
  • [NaN].includes(NaN) is true

From the proposal:

Motivation

When using ECMAScript arrays, it is commonly desired to determine if the array includes an element. The prevailing pattern for this is

if (arr.indexOf(el) !== -1) {
    ...
}

with various other possibilities, e.g. arr.indexOf(el) >= 0, or even ~arr.indexOf(el).

These patterns exhibit two problems:

  • They fail to "say what you mean": instead of asking about whether the array includes an element, you ask what the index of the first occurrence of that element in the array is, and then compare it or bit-twiddle it, to determine the answer to your actual question.
  • They fail for NaN, as indexOf uses Strict Equality Comparison and thus [NaN].indexOf(NaN) === -1.

Proposed Solution

We propose the addition of an Array.prototype.includes method, such that the above patterns can be rewritten as

if (arr.includes(el)) {
    ...
}

This has almost the same semantics as the above, except that it uses the SameValueZero comparison algorithm instead of Strict Equality Comparison, thus making [NaN].includes(NaN) true.

Thus, this proposal solves both problems seen in existing code.

We additionally add a fromIndex parameter, similar to Array.prototype.indexOf and String.prototype.includes, for consistency.


Further information:

  • SameValueZero algorithm
  • Strict Equality Comparison algorithm
2 of 11
50

Technically

  • NaN or undefined will not be findable when using indexOf.
[NaN].indexOf(NaN) // => -1 (not found)
[NaN].includes(NaN) // => true

[undefined].indexOf(undefined) // => -1 (not found)
[undefined].includes(undefined) // => true
  • includes also is of no use if you want to know at where index the element was found.

  • While searching a string, includes accepts regexpes as opposed to indexOf

Readability

  • arr.includes('searchedElement') does what it says and it is obvious that it returns a boolean.
  • while arr.indexOf('searchedElement') !== -1 to know if something exists in a string or an array is less more readable.

Performances

According to this article on the subject there are no noticeable difference although includes may be a very little bit slower.

History

indexOf was created way before includes.

Browser support

  • indexOf => 97.08%
  • includes=> 97.51%

So both can be used safely.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › includes
Array.prototype.includes() - JavaScript | MDN
The includes() method of Array instances determines whether an array includes a certain value among its entries, returning true or false as appropriate.
🌐
Tpiros
tpiros.dev › blog › contains-vs-includes
contains vs includes - Tamas Piros
November 30, 2021 - As it turns out the DOMTokenList looks and feels like an array, but it is not one. There are properties and some methods that we can access on it that would make us believe that we are dealing with an array but it is a separate interface. And henceforth, instead of using includes() we need to use contains().
🌐
W3Schools
w3schools.com › jsref › jsref_some.asp
JavaScript Array some() Method
The some() method checks if any array elements pass a test (provided as a callback function).
🌐
Webdevtutor
webdevtutor.net › blog › typescript-some-vs-includes
TypeScript `some()` vs `includes()`: Understanding the Difference
In this example, the some() method returns true because at least one element (4 and 5) in the array satisfies the predicate function (num > 3). The includes() method checks if an array includes a specific value.