I'm trying to count the number of occurrences in one array of objects and return another array with that occurrences.
var data = [
{
absCost: 0,
absEndDate: "2014-04-24T00:00:00+01:00",
absId: "#",
absMins: 3152,
absStartDate: "2015-04-08T00:00:00+01:00",
absType: "Annual Leave",
absenceReason: "",
authorise: "Undecided",
department: "St Catherine's Ward",
empName: "Alison Lane",
empNo: " 06547",
empid: 575,
status: "",
year: 2014
},{
absCost: 0,
absEndDate: "2015-04-24T00:00:00+01:00",
absId: "#",
absMins: 3152,
absStartDate: "2015-04-08T00:00:00+01:00",
absType: "Annual Leave",
absenceReason: "",
authorise: "Undecided",
department: "St Catherine's Ward",
empName: "Alison Lane",
empNo: " 06547",
empid: 575,
status: "",
year: 2015
},
{
absCost: 0,
absEndDate: "2015-04-24T00:00:00+01:00",
absId: "#",
absMins: 3152,
absStartDate: "2015-04-08T00:00:00+01:00",
absType: "Annual Leave",
absenceReason: "",
authorise: "Undecided",
department: "St Catherine's Ward",
empName: "Alison Lane",
empNo: " 06547",
empid: 575,
status: "",
year: 2015
}];
var finalArray = [];
for (var idx=0; i>data.length; i++){
finalArray.push({
year: data[i].year,
frequency: //number of occurrences of the Year
});
}
//Hi Would like to get this result:
/*
finalArray=[{
year: 2014,
frequency: 1
},{
year: 2015,
frequency: 2
}]; */
i < data.length, withi > data.lengthyou will not execute anything (ifidxshould bei, if not you are so far)Array.filtera try.