Get the App
SLTechnology News&Howtos  ›  Development  › 

How to delete array elements by vue.js

Shulou Source: shulou.com Published: 2022-06-03 07:07:43 11月15日 Update

This article mainly shows you "vue.js how to delete array elements", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "vue.js how to delete array elements" this article.

Vue.js method to delete array elements: 1, get the subscript of the elements that need to be deleted in the array; 2, calculate from the subscript, delete the element whose length is length.

The operating environment of this paper: windows10 system, vue.js 2.9, thinkpad T480 computer.

Do you remember that there is a method arr.splice (arr.indexOf (ele), length) that can help us delete any js array, which is very useful.

The arr.splice (arr.indexOf (ele), length) method means to first get the subscript of this element in the array, and then calculate from this subscript to delete the element of length length.

Code example:

Delete / / introduce jqueryexport default {data () {return {users: [{name:'zx', age:18 Addrress:' Nanjing, Jiangsu', email:'1773203101@qq.com', contacted:false,} {name:'zhiyi', age:19, addrress:' Beijing, China', email:'1773203101@qq.com' Contacted:false,}, {name:'zhuxu', age:20 Addrress:' Shanghai, China', email:'1773203101@qq.com', contacted:false,},]}} Methods: {deleteUser:function (user) {/ / means to get the subscript of this element first Then, starting with this subscript, delete the element this.users.splice (this.users.indexOf (user), 1) of length 1. The above is all the content of the article "how to delete array elements in vue.js". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Element array subscript method content article length help China learning utility code easy to understand more organization environment computer knowledge example system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Apple OPPO Reno Huawei Shulou Technology