1

I have an object list with a large number of elements of Test:

Test:{name:'', creator:''}

Require to extract a unique creators list from that list. I have tried:

const creators = Array.from(new Set(tests.map(t=>t.creator))

This works fine but, due to rapid changes, I have to call this again and again. So, this takes more time and lags the UI. How to build this array more efficiently than the current implementation?

EDIT:

Context information:

Require unique element array(not set) due to rendering on UI by

tests.map(test=><Test data={test}/>)

Nilanka Manoj
  • 3,527
  • 4
  • 17
  • 48

1 Answers1

-2

You can use lodash library's function "uniqBy" to overcome this issue.

Documentation: https://lodash.com/docs#uniqBy

Example:-

_.uniqBy(data, function (e) {
  return e.creator;
});
Mohit Arora
  • 102
  • 1
  • 7