JavaScript array.findIndex() Function

JavaScript Logo

array.findIndex() – Returns the **index** of the first element that satisfies the testing function or `-1`.

๐Ÿ‘‰ Syntax

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

๐Ÿงช Example

const nums=[4,9,16];
console.log(nums.findIndex(n => n > 10)); // 2

Comments