I want manipulate JSON input data and output it in different objects,
for example the data below will be as input:
const data= [{"code": "500", "dayTime": "On MON 11AM - 13PM", "group_id":"012021106667", "location": "A0716", "scanningTime": "2021-01-22T06:10:40.000Z", "subjectName": "PROGRAMMING"},
{"code": "1303", "dayTime": "On FRI 9AM - 11AM", "group_id": "01202110666", "location": "A0715", "scanningTime": "2021-01-22T06:37:11.000Z","subjectName": "DISTRIBUTED SYSTEM"},
{"code": "503", "dayTime": "On MON 11AM - 13PM", "group_id":"012021106667", "location": "A0716", "scanningTime": "2021-01-22T06:10:40.000Z", "subjectName": "CLIENT SERVER"}]
As you can see in the object I have three subjects names and each one has unique code. I want to take every code data into new object, in other words, based on the data I should have three objects each one have the subject data related to the code.
the expected outcome should look something like this:
const data1= [{"code": "500", "dayTime": "On MON 11AM - 13PM", "group_id":"012021106667", "location": "A0716", "scanningTime": "2021-01-22T06:10:40.000Z", "subjectName": "PROGRAMMING"}]
const data2= [{"code": "1303", "dayTime": "On FRI 9AM - 11AM", "group_id": "01202110666", "location": "A0715", "scanningTime": "2021-01-22T06:37:11.000Z","subjectName": "DISTRIBUTED SYSTEM"}]
const data3= [{"code": "503", "dayTime": "On MON 11AM - 13PM", "group_id":"012021106667", "location": "A0716", "scanningTime": "2021-01-22T06:10:40.000Z", "subjectName": "CLIENT SERVER"}]
I used forEach
to assign the data to new object, but how to assign it based on "code" item and make it like loop every data with different code assign it to new object
thanks in advance
question from:
https://stackoverflow.com/questions/65840570/filter-object-data-and-split-it-into-several-objects-in-react-native 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…