How to delete array elements in vue

青灯夜游
Release: 2022-03-07 15:55:19
Original
12763 people have browsed it

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)".

How to delete array elements in vue

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);
Copy after login

Method 2: Use filer

const list  =  listArr.filter ( item => item.check)  //过滤 listArr中不要 删除的 符合你要求的元素
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!