The includes() method

const fruits = ["apple", "banana", "cherry"];
console.log(fruits.includes("banana"));  // true
console.log(fruits.includes("grape"));   // false

One thing to remember: includes() is case-sensitive, so "Banana" would not match "banana".

Check objects with some()

const users = [{ id: 1 }, { id: 2 }];
const hasUserTwo = users.some((u) => u.id === 2);
console.log(hasUserTwo);  // true

Because objects are compared by reference, includes() will not find them by contents — use some() with a test instead.

Find the position with indexOf()

const nums = [10, 20, 30];
if (nums.indexOf(20) !== -1) {
  console.log("found it");
}

indexOf() returns the position of the value, or -1 when it is not present.

Which approach should you use?

  • includes() — the go-to yes/no check for primitive values.
  • some() — when checking objects or any custom condition.
  • indexOf() — when you also need the position of the match.
  • Common mistake: using includes() on objects and expecting a content match.

Frequently asked questions

includes() or indexOf()?

Use includes() when you only need a true/false answer — it reads better and handles NaN correctly. Use indexOf() when you also need the position.

Why does includes() not find my object?

Objects are compared by reference, not by value, so two objects with the same contents are not equal. Use some() with a comparison instead.

Build a solid base with our free JavaScript course.