I am working on an angular application. I have to read data from json and process in two parts.
Read data from json using express: I have following Json in alphabetically sorted order.
{ "1": "Andy", "2": "Billy" "3": "Carry" "4": "Doda" }
Left hand side are Id's and Right one's are names. I have to read this data using express and access this data in my angular component.
In my angular component I have another array which is also sorted. That array is as follows:
[ { "Name": "Andy", "Id": "1" "IncomingTime": "2020-06-19T11:02+00:00", "Outgoingtime": "2020-06-19T11:07+00:00" }, { "Name": "Billy", "Id": "2" "IncomingTime": "2020-06-19T11:05+00:00", "Outgoingtime": "2020-06-19T11:17+00:00" }, { "Name": "Ciena", "Id": 5 "IncomingTime": "2020-06-19T11:05+00:00", "Outgoingtime": "2020-06-19T11:07+00:00" }, { "Name": "Doda", "Id": "4" "IncomingTime": "2020-06-19T11:05+00:00", "Outgoingtime": "2020-06-19T11:07+00:00" } ]
Once above Json data is available in component(JSON in point 1), I have to make a new array(or any data structure which can be sorted). In that new array I have to put data in such a way that alphabetically sorted "Name" coming from above Json should match with with data in sorted array. If Name is matched then content(Name, id, IncomingTime , OutgoingTime) is copied to new array for that particular "Name" which will also be sorted. If suppose While comparing names we came across a name for which data is not there in sorted array, we need to keep only Name in new array doesn't matter data is there or not. Like in above data for "Carry" data is not there in sorted array still in final array "Carry" should be there. How can I do that?