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']