JavaScript .some() — Overview
.some()checks whether at least one element in an array satisfies a given condition.
Method used for:
Checking if at least one item in an array matches a condition
Validating forms or inputs
Conditional UI rendering
Searching inside objects or arrays of objects (where
.includes()fails)
Syntax
array.some(callbackFn);
callbackFn(element, index, array)
for each item in the array:
run callbackFn → if callbackFn returns true → stop and return true,
if no item returned true → return false
When to use .some()
Use it whenever your condition is dynamic or involves logic, not just a simple value check.
.includes() → checks value directly.some() → checks logic / condition
Example 1 — Check if an array has any even number
const nums = [1, 3, 5, 8];
console.log(nums.some(n => n % 2 === 0)); // true
Explanation:8 is even → so .some() returns true.
Example 2 — Checking if any user is admin
const users = [
{ name: "Aman", role: "user" },
{ name: "Riya", role: "admin" }
];
const isAdminPresent = users.some(u => u.role === "admin");
console.log(isAdminPresent); // true
Explanation:
At least one user has role "admin" → true.
Example 3 — Common in React (conditional UI)
const users = [
{ name: "Aman", online: true },
{ name: "Riya", online: false }
];
return (
<>
{users.some(u => u.online) && <p>Someone is online</p>}
</>
);
Explanation:.some() makes conditional rendering easy.
Example 4 — Search bar filtering: check if ANY character matches
const tags = ["javascript", "react", "node"];
const query = "re";
const result = tags.some(tag =>
tag.toLowerCase().includes(query.toLowerCase())
);
console.log(result); // true
Example 5 — Validate form inputs
const fields = ["name", "email", ""];
const hasEmpty = fields.some(f => f.trim() === "");
console.log(hasEmpty); // true
Explanation:
One field is empty → true.
Example 6 — Checking nested data
const orders = [
{ id: 1, items: [] },
{ id: 2, items: ["apple"] }
];
console.log(orders.some(o => o.items.length > 0)); // true
{ id: 1, items: [] }
items.length→ 0
0 > 0→ false{ id: 2, items: ["apple"] }
items.length→ 1
1 > 0→ true ← this is enough
Common mistake
❌ Wrong:
users.includes({ name: "abhinav" });
.includes() can’t check object values — only reference.
✔ Correct:
console.log(users.some(u => u.name === "abhinav")) // true
Quick summary
.includes()→ checks for a specific value.some()→ checks if any item meets a condition.some()works great with arrays of objects

