I have this data inside my controller form:
$scope.reports = [ { departuredate:"2015-03-10", routeline:"PASAY - CAGAYAN", seatingtypescode:"ABS", tickettripcode:"3", tripcodetime:"16:30:00" }, { departuredate:"2015-03-10", routeline:"PASAY - CAGAYAN", seatingtypescode:"ABS", tickettripcode:"3", tripcodetime:"16:30:00" } ];
The above data is array of objects, I want them to convert in array. I used this code below to convert them in array:
var details=[]; for(var index in $scope.reports){ var tripcode = $scope.reports[index].tickettripcode; var dateOfDepature = $scope.reports[index].departuredate.split('-'); details.push(tripcode, dateOfDepature[2]); } if(details[tripcode][dateOfDeparture[2]]){ details[tripcode][dateOfDeparture[2]] = details[tripcode][dateOfDeparture[2]] +1; } else { details[tripcode][dateOfDeparture[2]] =1; }
The code is not working fine with me and I do not know why. I have a doubt if I am doing array manipulation in a right way. I have error dateOfDeparture is not defined
. I already defined the dateOfDeparture
so why I getting this error. I just wanted to get the output which looks like this:
details = Array ( [3] =>Array ( [10] =>2 ) )
The [3]
is tickettripcode and [10]
is the day of depaturdate. The 2 means number of departuredate in that date.
Any help would be much appreciated. This is the link of my fiddle : https://jsfiddle.net/n1bw2u36/ Thanks in advance!