0

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'.

1 Answer 1

4

Just try with:

$scope.filtered_items = $scope.items.map(function(item){
  return [item.name, item.value];
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.