js:map转list
时间: 2023-10-13 20:03:38 浏览: 123
在JavaScript中,可以使用以下代码将Map转换为List:
```javascript
let map = new Map();
// 假设map已经有了键值对
let list = Array.from(map.values());
console.log(list);
```
这个代码通过Map的`values()`方法获取所有的值,并使用`Array.from()`方法将其转换为数组。然后,你可以将这个数组用于进一步的操作。请注意,这里的`map`是指前面提到的代码中的`map`对象。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* [js中map和list互转](https://blog.csdn.net/qq_15769147/article/details/91960270)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *3* [List转Map的三种方法](https://blog.csdn.net/web17886480312/article/details/126434810)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文