

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the use of Array.findIndex() method in JavaScript?
Array.findIndex()
Array.findIndex() returns the first index of the array element that pass a test implemented by the provided function. This method executes the function once for each element that is present in array.If once the condition of the function satisfied, Index of the first element that satisfied the condition will be returned, if not value '-1 ' will be returned.
Once an element satisfies the provided condition then findIndex() does't check other values.In the following example findIndex() method check whether the salary elements are greater than the given salary 15000.Since the first element to satisfy the condition is 17000 it won't check the other values such as 28000 and 30000 and returns the index of 17000.
Example
<html> <body> <p id="findindex"></p> <script> var wages = [6000, 10000, 17000, 28000, 30000]; function checkSal(wage) { return wage >= 15000; } document.getElementById("findindex").innerHTML = wages.findIndex(checkSal); </script> </body> </html>
Output
2
- Related Questions & Answers
- What is the use of forEach() method in JavaScript?
- What is the use of Math.pow() method in JavaScript?
- What is the use of substr() method in JavaScript?
- what is the use of slice() method in JavaScript?
- What is the use of Array.entries() method in JavaScript?
- What is the use of charAt() method in JavaScript?
- What is the use of Array.Reduce() method in JavaScript?
- What is the use of Array.Some() method in JavaScript?
- What is the use of Array.Find() method in JavaScript?
- What is the use of Math.abs() method in JavaScript?
- What is the use of Object.is() method in JavaScript?
- What is the use of Atomics.store() method in JavaScript?
- What is the use of Object.isFrozen() method in JavaScript?
- What is the use of weakSet.has() method in JavaScript?
- What is the use of _.size() method in JavaScript?
Advertisements