I'm trying to create a dynamically generating table in javascript and I have a JSON that I need to filter specific information out of
JSON to pull from (courseList)
let courseList = [
{
"Line": 81,
"Department": "BUS",
"Number": 344,
"Section": 1,
"Title": "MANAGEMENT OF INFORMATION SYSTEMS",
"Faculty": "Smith, John",
"Openings": 2,
"Capacity": 30,
"Status": "Open",
"Day": "MWF",
"StartTime": "1:25:00 PM",
"EndTime": "2:20 PM",
"Campus": " Main Campus",
"Building": " Science and Engineering",
"Room": " SE 341 Computer Science Lab",
"Credits": 3,
"Start Date": "8\/30\/2021",
"End Date": "12\/17\/2021\r\n"
},
{
"Line": 167,
"Department": "CSC",
"Number": 133,
"Section": 2,
"Title": "SURVEY OF COMPUTER SCIENCE",
"Faculty": "Scott, John",
"Openings": 6,
"Capacity": 15,
"Status": "Open",
"Day": "H",
"StartTime": "2:00:00 PM",
"EndTime": "4:50 PM",
"Campus": " Main Campus",
"Building": " Science and Engineering",
"Room": " SE 341 Computer Science Lab",
"Credits": 0,
"Start Date": "8\/30\/2021",
"End Date": "12\/17\/2021\r\n"
}
]
And I would like to run some kind of method to generate another JSON from the existing one. To look something like this
Expected result
let filteredCourses = [
{
"Title": "MANAGEMENT OF INFORMATION SYSTEMS",
"Faculty": "Smith, John",
"Openings": 2,
},
{
"Title": "SURVEY OF COMPUTER SCIENCE",
"Faculty": "Scott, John",
"Openings": 6,
}
]
I'm still new to javascript but I know there is a filter method on arrays that I have used, but that only gave me the keys or the values from my coursesList. I have also tried using the push method without much luck.
Is there some way to either filter out the specific key and value pairs that I need directly into a JSON, or can I filter out both the keys and values separately and combine them? I'm not sure what the best method would be.