<template>
<div>
<button @click="myClick">过滤数组</button>
</div>
</template>
<script>
export default {
data () {
return {
allName: 'nick',
list: [
{
id: 0,
name: 'jack'
},
{
id: 1,
name: 'nick'
},
{
id: 2,
name: 'Lili'
}
]
}
},
methods: {
myClick () {
let obj = this.list.find(item => {
return item.name === this.allName
})
console.log(obj) // 输入内容为 {id: 1,name: 'nick'}
},
}
}
</script>
10-07
2万+
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)