let a=[ {uuid: '1675778946615054337', PageName: '场景'}, {uuid: '1675778892328177665', PageName: '行业'}, {uuid: '1675784193018269698', PageName: '新能源远'}, {uuid: '1675784225587040258', PageName: '水利环境'}, {uuid: '1675784252438974465', PageName: '医疗健康'}, {uuid: '1677193227430080513', PageName: '智慧工厂'}, {uuid: '1679056245520674818', PageName: '智慧园区'}, ] let b=[ "1675778946615054337",1675784193018269698 ] vue中怎么通过筛选吧b数组的数据和a数组里面的数据的uuid相匹配,然后返回相匹配的PageName的数组
时间: 2023-12-24 16:05:57 浏览: 128
在 Vue 中,你可以使用 `Array.prototype.filter()` 方法和 `Array.prototype.includes()` 方法来筛选数组数据并返回匹配的结果。下面是一个示例代码,演示如何通过筛选 `b` 数组的数据并与 `a` 数组中的 `uuid` 相匹配,然后返回匹配的 `PageName` 数组:
```javascript
let a = [
{ uuid: '1675778946615054337', PageName: '场景' },
{ uuid: '1675778892328177665', PageName: '行业' },
{ uuid: '1675784193018269698', PageName: '新能源远' },
{ uuid: '1675784225587040258', PageName: '水利环境' },
{ uuid: '1675784252438974465', PageName: '医疗健康' },
{ uuid: '1677193227430080513', PageName: '智慧工厂' },
{ uuid: '1679056245520674818', PageName: '智慧园区' },
];
let b = [
"1675778946615054337", "1675784193018269698"
];
let matchedPageNames = a.filter(item => b.includes(item.uuid)).map(item => item.PageName);
console.log(matchedPageNames);
```
这段代码会输出匹配的 `PageName` 数组,即 `['场景', '新能源远']`。你可以根据需要将其应用到你的 Vue 项目中。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)