I have an array of some objects
array = [{‘code’:’a’, ‘number’:’1’},
{‘code’:’b’, ‘number’:’2’},
{‘code’:’d, ‘number’:’3’},
{‘code’:’d’, ‘number’:’3’},
{‘code’:’c’, ‘number’:’4’},
{‘code’:’e, ‘number’:’5’}]
I would like the expected output to be
[‘a’,’b’,’c’,'d',’e’]
array.filter((values, index, self) => index === self.findIndex(i => i.code === values.code)).map(values => values.code))
Current result is:
[‘a’,’b’,’d’,’c’,’e’]
I was able to remove the duplicates but don’t know how to change the order without changing too much on current method. Appreciate a lot if someone can help me on this!