Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete array elements by vue

Shulou Source: shulou.com Published: 2022-06-01 06:52:30 09月18日 Update

This article mainly explains "vue how to delete array elements", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "vue how to delete array elements" bar!

Delete method: 1, use forEach to traverse the array, use the splice method to delete the subscript index, syntax "this.splice (index, 1);"; 2, delete with filer (), syntax "listArr.filter (item= > item.check)".

The operating environment of this tutorial: windows7 system, vue2.9.6 version, DELL G3 computer.

To do a project using the front-end vue framework, you need to loop through to delete some array elements. At the beginning of thinking limitations, has been obsessed with how to loop delete, hesitant to loop delete array value subscript will change, is not a good method.

Method 1: use forEach and splice

Delete an element: use the splice method to delete the element with the subscript index

This.splice (index, 1)

Method 2: use filer

Const list = listArr.filter (item = > item.check) / / filter the elements in listArr that do not meet your requirements

And assign the elements not to be deleted to the original array

Thank you for reading, the above is the content of "how to delete array elements in vue". After the study of this article, I believe you have a deeper understanding of how to delete array elements in vue, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Elements arrays methods subscripts learning loops content grammar hesitation front-end that is ideas ideas situations tutorials articles more frames environments computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Linux Shulou Information Redmi OPPO Reno