
- 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
Fetch specific values from array of objects in JavaScript?
Let’s say the following are our array of objects:
const details = [ { employeeFirstName: "John", employeeLastName: "Doe" }, { employeeFirstName: "David", employeeLastName: "Miller" }, { employeeFirstName: "John", employeeLastName: "Smith" } ]
Example
Following is the code to fetch specific values, in this case with first name “John” −
const details = [ { employeeFirstName: "John", employeeLastName: "Doe" }, { employeeFirstName: "David", employeeLastName: "Miller" }, { employeeFirstName: "John", employeeLastName: "Smith" } ] for (var index = 0; index < details.length; index++) { if (details[index].employeeFirstName === "John") { console.log("FirstName=" + details[index].employeeFirstName + " LastName= " + details[index].employeeLastName); } }
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo223.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo223.js FirstName=John LastName= Doe FirstName=John LastName= Smith
- Related Articles
- Get only specific values in an array of objects in JavaScript?
- Fetch specific documents with array values in MongoD
- Fetch alternative even values from a JavaScript array?
- Fetch values by ignoring a specific one in JavaScript?
- MySQL query to fetch specific records matched from an array (comma separated values)
- Create a record array from a (flat) list of array and fetch specific values based on index in Numpy
- Fetch specific field values in MongoDB
- Filter array of objects by a specific property in JavaScript?
- Find specific key value in array of objects using JavaScript
- Accessing array values in a MongoDB collection to fetch a specific document
- Add values of matching keys in array of objects - JavaScript
- Sum of array object property values in new array of objects in JavaScript
- Sorting an array of objects by property values - JavaScript
- Sum similar numeric values within array of objects - JavaScript
- Search from an array of objects via array of string to get array of objects in JavaScript

Advertisements