Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

Original array of objects:

$scope.items = [
    {
        'name': 'Apple',
        'value': 10,
        'color': 'green',
        'size': 'medium'
    },
    {
        'name': 'Kiwi',
        'value': 12,
        'color': 'brown',
        'size': 'small'
    },
    {
        'name': 'Lemon',
        'value': 8,
        'color': 'yellow',
        'size': 'small'
    }
];

I want to return:

$scope.filtered_items = [
    ['Apple', 10],
    ['Kiwi', 12],
    ['Lemon', 8]
];

So, two things: first I want to convert an array of objects into an array of arrays and second, I want to only extract 'name' and 'value'.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Just try with:

$scope.filtered_items = $scope.items.map(function(item){
  return [item.name, item.value];
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.