0

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

1 Answer 1

3

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 };
})
Sign up to request clarification or add additional context in comments.

2 Comments

@Stweet is Timesheets.query async function, you need put your code to success callback
Arhhh now i understand, awesome ! Thx mate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.