---
# System prepended metadata

title: Javascript (含ES6)
tags: ['2023', 前端]

---

###### tags: `前端`,`2023`


# Javascript (含ES6)

## map 取得所需屬性

MAP() 特性:
* 回傳的值組合是一個新的陣列
* 並不會改變原陣列
* 回傳數量會等於原始陣列的長度
* 不回傳是 undefined 


```javascript=
let arr = [
    {
        id:1,
        wantData:'A'
    },
    {
        id:2,
        wantData:'B'
    },
    {
        id:3,
        wantData:'C'
    }
]
var result = arr.map((item) => { return item.wantData });
```


## 刪除重複元素

* Set
* filter

```javascript=
let arr = [1,1,2,2,3,4,5];

var result = [... new Set(arr)];

var filterResult = arr.filter((item,index) = > arr.indexOf(item) === index);
```

https://ithelp.ithome.com.tw/articles/10197716

{%hackmd BJrTq20hE %}