item.check)"."/> item.check)".">
Home > Article > Web Front-end > How to delete array elements in vue
Deletion method: 1. Use forEach to traverse the array, use the splice method to delete the element with the index index, the syntax is "this.splice(index, 1);"; 2. Use filer() to delete, the syntax is " listArr.filter(item=>item.check)".
The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.
When working on a project using the front-end vue framework, you need to loop through to delete some array elements. At first, my thinking was limited, and I kept struggling with how to delete in a loop. I hesitated that the subscript of the array value would change if I deleted it in a loop, which was not a good method.
Method 1: Use forEach and splice
Delete an element: Use the splice method to delete the element whose index is index
this.splice(index, 1);
Method 2: Use filer
const list = listArr.filter ( item => item.check) //过滤 listArr中不要 删除的 符合你要求的元素
and assign the elements not to be deleted to the original array
(Learning video sharing: vuejs tutorial, webfrontend)
The above is the detailed content of How to delete array elements in vue. For more information, please follow other related articles on the PHP Chinese website!