Vue.js method of traversing arrays: 1. Use a foreach loop, the code is [this.urls.forEach(item =>]; 2. Use a filter loop, the code is [return this.urls.filter (item =>】.
vue.js method of traversing arrays:
1, foreach
search(keyword){ var newList = [] this.urls.forEach(item =>{ if(item.name.indexOf(keyword) != -1){ newList.push(item) } }) return newList }
2、filter
search(keyword){ return this.urls.filter(item =>{ if(item.name.includes(keyword)){ return item } }) }
3, findIndex
del(row){ this.$confirm("确定要删除吗?", "删除").then(action=>{ var index = this.urls.findIndex(item =>{ if(item.name == row.name){ return true; } }) this.urls.splice(index, 1) });
4, some
del(row){ this.$confirm("确定要删除吗?", "删除").then(action=>{ this.urls.some((item, i) =>{ if(item.name == row.name){ this.urls.splice(i, 1) return true; } }) }); }
Related free learning recommendations:javascript(video)
The above is the detailed content of How vue.js traverses an array. For more information, please follow other related articles on the PHP Chinese website!