Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

3 of 3
Commonmark migration

You can use reduce() and Set combination for example. Read from the docs:

The Set object lets you store unique values of any type, whether primitive values or object references.

The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.

Please see a possible working solution.

const array = ['business>management', 'News>Entertainment News', 'business>Entrepreneurship'];
const result = array.reduce((a,c) => {
 c.split('>').forEach(e => a.add(e));
 return a;
}, new Set());
const unique = Array.from(result);
console.log(unique);

I hope that helps!

norbitrial
  • 15.2k
  • 10
  • 39
  • 66

AltStyle によって変換されたページ (->オリジナル) /