ジーノ:
ここで私が持っている配列の例は次のとおりです。
var array= ['business>management', 'News>Entertainment News', 'business>Entrepreneurship'];
私はこの結果をしたいです:
['business', 'management', 'News', 'Entertainment News', 'Entrepreneurship']
これは、この「>」重複とは別に、意味します
これは私がでてるところの一例であるが、それは単に矢印「>」削除jsfiddle
norbitrial:
あなたは使用することができますreduce()
し、Set
例えば組み合わせ。ドキュメントから読みます
Set
オブジェクトは、プリミティブ値またはオブジェクト参照かどうかは、どのようなタイプのユニークな値を格納することができます。
reduce()
この方法は、単一の出力値が得られ、配列の各要素に(あなたが提供する)減速機能を実行します。
可能な実用的なソリューションをご参照ください。
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);
私はそれが役に立てば幸い!