JavaScript - Find Index of a Value in Array Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report Here are some effective methods to find the array index with a value in JavaScript.Using indexOf() - Most Used indexOf() returns the first index of a specified value in an array, or -1 if the value is not found. JavaScript const a = [10, 20, 30, 40, 50]; // Find index of value 30 const index = a.indexOf(30); console.log(index); // Value not found const notFound = a.indexOf(60); console.log(notFound); Output2 -1 Using findIndex() for Complex ConditionsfindIndex() is used for finding the index of an element based on complex conditions. It takes a callback function that can include any logic for locating an item within the array. JavaScript const a = [10, 15, 20, 25, 30]; // Find index of first value greater than 18 const index = a.findIndex(value => value > 18); console.log(index); Output2 Using for Loop for Custom SearchUsing a for loop gives you complete control over how you search for items. You can stop the loop as soon as you find what you’re looking for, making it a flexible option for setting custom rules. JavaScript const a = [5, 10, 15, 20, 25]; let index = -1; // Find index of value 20 for (let i = 0; i < a.length; i++) { if (a[i] === 20) { index = i; break; } } console.log(index); Output3 Using lastIndexOf() for Reverse SearchIf you need the last occurrence of a value you can use lastIndexOf() method which returns the index of the last match, or -1 if the value is not found. This is useful what an arrays contain duplicate values. JavaScript const a = [5, 10, 15, 10, 5]; // Find last index of value 10 const index = a.lastIndexOf(10); console.log(index); Output3 Importance of Finding Array IndicesFinding array indices is essential forData Manipulation: Helps identify and modify elements based on their position.Search Optimization: Enables targeted data retrieval for better performance.Conditional Processing: Allows for specific actions on elements that meet criteria.Find the Array Index with a Value in JavaScript Comment More info L laxmigangarajula03 Follow Improve Article Tags : JavaScript Web Technologies javascript-array JavaScript-DSA JavaScript-Questions +1 More Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like