Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var arr = ["level^courses",
- "{\"id\":0,\"firstname\":\"Angel\",\"lastname\":\"Ivanov\",\"town\":\"Plovdiv\",\"role\":\"student\",\"grades\":[\"5.89\"],\"level\":2,\"certificate\":false}",
- "{\"id\":1,\"firstname\":\"Mitko\",\"lastname\":\"Nakova\",\"town\":\"Dimitrovgrad\",\"role\":\"trainer\",\"courses\":[\"PHP\",\"Unity Basics\"],\"lecturesPerDay\":6}",
- "{\"id\":2,\"firstname\":\"Bobi\",\"lastname\":\"Georgiev\",\"town\":\"Varna\",\"role\":\"student\",\"grades\":[\"5.59\",\"3.50\",\"4.54\",\"5.05\",\"3.45\"],\"level\":4,\"certificate\":false}",
- "{\"id\":3,\"firstname\":\"Ivan\",\"lastname\":\"Ivanova\",\"town\":\"Vidin\",\"role\":\"trainer\",\"courses\":[\"JS\",\"Java\",\"JS OOP\",\"Database\",\"OOP\",\"C#\"],\"lecturesPerDay\":7}",
- "{\"id\":4,\"firstname\":\"Mitko\",\"lastname\":\"Petrova\",\"town\":\"Sofia\",\"role\":\"trainer\",\"courses\":[\"Database\",\"JS Apps\",\"Java\"],\"lecturesPerDay\":2}"
- ]
- mess(arr)
- function mess (input) {
- var result = {students:[], trainers:[]}
- for (var i = 1; i < input.length; i++) {
- var line = {}
- line = JSON.parse(input[i])
- // console.log(line)
- if (line['role']=='student'){
- result.students.push(line)
- }
- else if (line['role']=='trainer'){
- result.trainers.push(line)
- }
- }
- console.log(result)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement