JavaScriptArrayfind

Returns the first element in the array that satisfies the testing function.

Syntax

arr.find(callbackFn)

Example

Enter values below to update the example in real time.

const
users
id
name
user
find
console
const users = [
  { id: 1, name: "Alice" },
  { id: 2, name: "Bob" }
];
const user = users.find((u) => u.id === 2);
console.log(user?.name);   // "Bob"