1

I have an object array, products, with properties "categoryid, categoryname, name, price". I want to return an object array with just "categoryid, categoryname" from this but since categoryid exist multiple times, I want only the unique results.

I can get both fields with this code but it won't be unique.

_.map(products, _.partialRight(_.pick, ['categoryid', 'category']))

How can I make this unique?

nurp
  • 1,239
  • 2
  • 14
  • 23

1 Answers1

2

I could do it in two separate lines:

var uniq = _.uniqBy(vm.productList, 'categoryid');
vm.categories = _.map(uniq, _.partialRight(_.pick, ['categoryid', 'category']))
nurp
  • 1,239
  • 2
  • 14
  • 23