How can I map and return the values "Title" in React, with a JSON file that contains an ID for each record? For example:
{
"id001": {
"Title": "Title-1",
"Year": "1990",
"Rated": "PG-13"
},
"id002": {
"Title": "Title-2",
"Year": "1999",
"Rated": "PG-13"
},
...
}
Thank you so much!
CodePudding user response:
you will need to import the json file first. some references
const a = {
"id001": {
"Title": "Title-1",
"Year": "1990",
"Rated": "PG-13"
},
"id002": {
"Title": "Title-2",
"Year": "1999",
"Rated": "PG-13"
},
}
const titleArr = Object.keys(a).map(function(key, index) {
return a[key].Title;
});
console.log(titleArr)
