- 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
JavaScript How to get all 'name' values in a JSON array?
Let’s say the following is our JSON array −
var details = [ { "customerDetails": [ { "customerName": "John Smith", "customerCountryName": "US" } ] }, { "customerDetails": [ { "customerName": "David Miller", "customerCountryName": "AUS" } ] }, { "customerDetails": [ { "customerName": "Bob Taylor", "customerCountryName": "UK" } ] } ]
To get only the CustomerName values, use the concept of map() −
Example
var details = [ { "customerDetails": [ { "customerName": "John Smith", "customerCountryName": "US" } ] }, { "customerDetails": [ { "customerName": "David Miller", "customerCountryName": "AUS" } ] }, { "customerDetails": [ { "customerName": "Bob Taylor", "customerCountryName": "UK" } ] } ] var allCustomerName = details.map(obj=> obj.customerDetails[0].customerName); console.log(allCustomerName);
To run the above program, you need to use the following command −
node fileName.js.
Here my file name is demo206.js.
Output
PS C:\Users\Amit\javascript-code> node demo206.js [ 'John Smith', 'David Miller', 'Bob Taylor' ]
- Related Articles
- How to get all collections where collection name like '%2015%'?
- How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
- Remove '0','undefined' and empty values from an array in JavaScript
- How to use wildcards like $ ('#name*'), $ ('#name%') in jQuery selectors?
- How to get all unique values in a JavaScript array?
- JavaScript Remove all '+' from array wherein every element is preceded by a + sign
- How to convert a date object's content into json in JavaScript?
- Access property as a property using 'get' in JavaScript?
- Make an array of another array's duplicate values in JavaScript
- Update 'a' record with 'b' and 'b' with 'a' in a MySQL column (swap) with only 'a' and 'b' values?
- How to use 'const' keyword in JavaScript?
- How to get Euler's constant value in JavaScript?
- How to deal with 'Boolean' values in PHP & MySQL?
- How to make 'from' as column name in MySQL?
- How and why does 'z'['toUpperCase']() in JavaScript work?

Advertisements