
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Get Only Specific Values in an Array of Objects in JavaScript
Let’s say the following is our array of objects −
var details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }, ];
To get only specific values in an array of objects in JavaScript, use the concept of filter().
Example
var details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }, ]; var specificValuesFromArray = details.filter(obj => obj.studentMarks === 92 || obj.studentMarks === 98); console.log(specificValuesFromArray)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo177.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo177.js [ { studentName: 'John', studentMarks: 92 }, { studentName: 'Mike', studentMarks: 98 } ]
Advertisements