前端 js中 set, map區別

Set 對象相似於數組,且成員的值都是惟一的。web const arr = [1, 2, 3, 4, 5, 5, 4, 3, 2, 1]; const set = new Set(); arr.forEach(item => set.add(item)); console.log(set); // 1, 2, 3, 4, 5 // 數組快速去重 console.log([...new Set(
相關文章
相關標籤/搜索