我有一个列表如下:
list = ["a", "a", "b", "c", "d", "e", "a,b,f"]
我使用 new_Set(list) 并得到以下结果:
["a", "b", "c", "d", "e", "a,b,f"]
我想获得独特的对象,如何用“,”分割它们?
我需要的是:
["a", "b", "c", "d", "e", "f"]
您可以join
在整个数组中创建一个逗号分隔的字符串并将其拆分为,
:
new Set(String(list).split(","))
要么
new Set(list.join(",").split(","))
这是一个片段:
const list = ["a", "a", "b", "c", "d", "e", "a,b,f"],
unique = new Set(list.join(",").split(","))
console.log(
Array.from(unique)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句