
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to create a custom function similar to find() method in JavaScript?
Let’s say we have the following records of studentId and studentName and want to check a specific student name −
const studentDetails= [ { studentId:101, studentName:"John" }, { studentId:102, studentName:"David" }, { studentId:103, studentName:"Carol" } ]
Create a custom function to find by name. Following is the code −
Example
const studentDetails= [ { studentId:101, studentName:"John" }, { studentId:102, studentName:"David" }, { studentId:103, studentName:"Carol" } ] function findByName(name){ var flag=true; for(var i=0;i<studentDetails.length;i++){ if(studentDetails[i].studentName==name){ flag=true; break } else{ flag=false; } } if(flag==true){ console.log("The name found="+name); } else{ console.log("The name not found="+name); } } findByName("David");
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo106.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo106.js The name found=David
- Related Articles
- Implement a custom function similar to Array.prototype.includes() method using JavaScript
- Create a custom toLowerCase() function in JavaScript
- How to create a custom object in JavaScript?
- How to define custom sort function in JavaScript?
- How to create a custom listview in android?
- How to create a function from a string in JavaScript?
- Update all the zero values with a custom value in MySQL with a function similar to ISNULL()
- How to create custom select boxes with CSS and JavaScript?
- How to create a custom jQuery Plugin?
- Implementing a custom function like Array.prototype.filter() function in JavaScript
- How to invoke a JavaScript Function as a method?
- How to create a custom unchecked exception in Java?
- How to create a custom navigation drawer in Android?
- How to create custom actionbar in android?
- How to create custom attributes in C#?

Advertisements