item.check)"."/> item.check)".">

Home  >  Article  >  Web Front-end  >  How to delete array elements in vue

How to delete array elements in vue

青灯夜游
青灯夜游Original
2022-03-07 15:09:5912804browse

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);

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!

Statement:
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