語法:
Array.from(new Set(arr))
示例:
function unique10(arr) { //Set數據結構,它類似於數組,其成員的值都是唯一的 return Array.from(new Set(arr)); // 利用Array.from將Set結構轉換成數組 } console.log(unique10([1, 1, 2, 3, 5, 3, 1, 5, 6, 7, 4])); // 結果是[1, 2, 3, 5, 6, 7, 4]
轉自:https://blog.csdn.net/weixin_42412046/article/details/81459294