- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHPPhysics
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 creating an array from JSON data?
To create an array from JSON data, use the concept of map() from JavaScript. Let’s say the following is our data −
const studentDetails =[
{
name : "John"
},
{
name : "David"
},
{
name : "Bob"
}
];
Following is the code to create an array from the above data −
Example
const studentDetails =[
{
name : "John"
},
{
name : "David"
},
{
name : "Bob"
}
];
const ListOfStudentName =
studentDetails.map(({name:actualValue})=>actualValue);
console.log(ListOfStudentName);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo82.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo82.js [ 'John', 'David', 'Bob']
Advertisements