accoriEpipt
New Member
I need my two elements to go into my var busList like this (this is hardcoded): \[code\]var busList = [{ RuteNr: '901', RuteNavn: 'Vejle - Kolding'},{ RuteNr: '901-xs', RuteNavn: 'Kolding - Vejle'},{ RuteNr: '401', RuteNavn: 'Kastrup - arhus'}];\[/code\]But in the actual code, I am receiving it all in a list. Therefore I am doing it this way:\[code\] rutenr = data.busliste[counter].RuteNr; //this line works fine rutenavn = data.busliste[counter].RuteNavn; //this line works fine var busList = [{ RuteNr: rutenr , RuteNavn: rutenavn}];\[/code\]Unfortunately this doesn't work. The elements does not go into the array. Any help?EDIT: (complete code)\[code\] $.get('http://localhost:7120/LocationService/GetRouteList', function(data) { $('.result').html(data); var counter = 0; for (var i in data.busliste) { rutenr = data.busliste[counter].RuteNr; rutenavn = data.busliste[counter].RuteNavn; busList.push({ RuteNr: rutenr , RuteNavn: rutenavn}); counter++; }});\[/code\]