Han
1 min readJan 17, 2019

JS Array 刪除重複元素的三種方式

  1. Set(ES6): 最簡單,效率最高。
  2. Array.filter:常用的方式,目前個人習慣的寫法。除了可以用來找不重複元素,也可以反向來找到重複元素。
  3. Array.reduce:效率最差,看起來較不直觀。
An example of the JS code.

紀錄一下今天晚上看完的文章,順便練習一下JS,剛好最近也在看一些關於JS’s Set的相關語法,趁機寫下本文,以供後續查找。

參考:

  1. About the kinds of Timing deduplicating methods
  2. How to Remove Array Duplicates in ES6
  3. Remove duplicates from js array (ES5/ES6)

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Han
Han

No responses yet

Write a response