Reputation: 703
i tried many ways, but i don't have any clue how to get a single property of an array.
I want to make this Array1:
this.array1 = [{name: 'misko', gender: 'male'},{name: 'misko', gender: 'male'}];
And then i want to get only names from array 1 to an array but how like
this.array2 = [{'misko'},{'misko'}];
my code
this.getList = function() {
this.timesheets = Timesheets.query({
projectId: $scope.selected.project[0],
startWeek: this.weekStart,
endWeek: this.weekEnd
});
$log.log('1');
this.timesheetsId = this.timesheets.map(function (el) {
return { name: el._id };
$log.log('2');
});
};
i can see log 1 in console not log2
Upvotes: 0
Views: 55
Reputation: 77482
You can use map, like this
this.array1 = [{name: 'misko', gender: 'male'},{name: 'misko', gender: 'male'}];
this.array2 = this.array1.map(function (el) {
return { name: el.name };
})
Upvotes: 3