- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
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
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 } ]
- Related Articles
- Fetch specific values from array of objects in JavaScript?
- Search from an array of objects via array of string to get array of objects in JavaScript
- Sorting an array of objects by property values - JavaScript
- How to select objects where an array contains only a specific field in MongoDB?
- Filter array of objects by a specific property in JavaScript?
- Find specific key value in array of objects using JavaScript
- How to get only the first n% of an array in JavaScript?
- Add values of matching keys in array of objects - JavaScript
- Sum of array object property values in new array of objects in JavaScript
- Converting array of objects to an object of objects in JavaScript
- Get the max n values from an array in JavaScript
- How to get the first n values of an array in JavaScript?
- Get the number of true/false values in an array using JavaScript?
- How to get a specific object from array of objects inside specific MongoDB document?
- MongoDB query to get only specific fields in nested array documents?

Advertisements