- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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.Find() method in JavaScript?
Array.find()
Array.find() is used to return value of first element in the array that satisfies provided testing condition(user given condition).If the provided testing condition fails then array.find() returns undefined.In the following example array.find() checks whether the price elements in array are more than the given testing price(12000). If the provided testing condition true then first value that passed the test will be executed, if not undefined will be executed.
Example
<html>
<body>
<p id="price"></p>
<script>
var price = [3000, 21000, 28000, 20000, 15500];
function checkCost(cost) {
return cost >= 12000;
}
document.getElementById("price").innerHTML = price.find(checkCost);
</script>
</body>
</html>
Output
21000
Advertisements