I need to add a value to an array based on certain conditions.
My code looks something like this:
var newEmployee = [];
$scope.employees = [{'id':1, 'new':true},{'id':2, 'new':false}{'id':3, 'new':false}];
newEmployee = $scope.employees.filter(function(employee){
if(employee.new) {
return employee.id;
}
});
However, when I console.log(newEmployee)
, the output is:
{'id':1, 'new':true}
instead of just the id [1]
.
I'm not sure where I went wrong. Any help would be greatly appreciated. Thank you!