JavaScript array.find() Function

JavaScript Logo

array.find() – Returns the **first element** that satisfies the provided testing function or `undefined`.

๐Ÿ‘‰ Syntax

element = array.find((element, index, array) => {
  return /* condition */;
}, thisArg);

๐Ÿงช Example

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

Comments