Sobes.tech
Middle

What is the difference between some and includes?

sobes.tech AI

Answer from AI

some and includes are array methods in JavaScript, but they serve different purposes:

  • some checks if at least one element in the array satisfies the condition specified in the provided function. It returns true or false.

  • includes checks if the array contains a specific value. It returns true or false.

Example:

const arr = [1, 2, 3, 4];

// some: check if there is a number greater than 3 in the array
console.log(arr.some(x => x > 3)); // true

// includes: check if the number 3 is in the array
console.log(arr.includes(3)); // true
What is the difference between some and includes… - sobes.tech