# JS删除重复元素

**URL:** <https://www.shiqidu.com/t/topic/581>\
**Category:** 开发调优\
**Tags:** JavaScript\
**Created:** [2019 年4 月 18 日 03:37 UTC](https://www.shiqidu.com/t/topic/581 "2019-04-18T03:37:56Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Leon](https://www.shiqidu.com/user_avatar/www.shiqidu.com/leon/32/5_2.png) [@Leon](https://www.shiqidu.com/u/Leon)\
发布日期： [2019 年4 月 18 日 03:37 UTC](https://www.shiqidu.com/t/topic/581/1 "2019-04-18T03:37:56Z")

</div>

使用filter函数可以很简单的实现这个功能

```js
var r, array = ['apple', 'strawberry', 'banana', 'pear', 'apple', 'orange', 'orange', 'strawberry'];
r = array.filter(function (element, index, self) {
    return self.indexOf(element) === index;
});
console.log(r.toString());
// apple,strawberry,banana,pear,orange

```
