Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Understanding the find() method to search for a specific record in JavaScript?
To fetch a specific record, use find() with some condition.
Example
Following is the code −
var obj=[
{
studentId:101,
studentName:"John"
},
{
studentId:102,
studentName:"Bob"
},
{
studentId:103,
studentName:"David"
}
]
const result = obj.find(
(o) =>
{
return o.studentId === 102
}
);
console.log(result);
To run the above program, you need to use the below command −
node fileName.js.
Here, my file name is demo315.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo315.js
{ studentId: 102, studentName: 'Bob' } Advertisements
