I have an object that contains an array and a couple of other values that I need to pass to the backend, but the backend needs to receive it as an array of objects. I fill in an array ($scope.student) by using checkboxes and the other values (docentid, vakid, klasid) by clicking on a field.
The object with the array and values:
$scope.user = {
studentid: [$scope.student],
vakid: '',
klasid: ''
};
The mapping function:
var dataToSend = [$scope.user.studentid].map(function(s) {
return {
vakid: $scope.user.vakid, klasid: $scope.user.klasid, studentid: s
};
});
Right now, when I log user, I see:
Object {studentid: Array[5], //Amount of results checked
vakid: "Alfreds Futterkiste",
klasid: "Berlin"}
I would like to make it into an array of multiple objects, so every object will have the unique values of the array, vakid and klasid. The mapping function returns an empty array with vakid, klasid and studentid empty.
What am I doing wrong?