Home >Web Front-end >Vue.js >How to delete array elements in vue

How to delete array elements in vue

青灯夜游
青灯夜游Original
2021-10-27 14:11:1264650browse

Vue method of deleting array elements: 1. Use the "delete array name [subscript]" statement; 2. Use the "arr.splice (starting position, number)" statement; 3. Use "this.$ delete(array,1)" statement; 4. Use the "this.a.$remove('element value')" statement.

How to delete array elements in vue

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

Vue’s method of deleting array elements

deleteOnly the deleted elements become empty/undefined Others The key value of the element remains unchanged.

spliceDeletes the array directly Changes the key value of the array.

Vue.deleteDeletes the array directly Changes the key value of the array.

<script type="text/javascript">
	var a=[1,2,3,4]
	var b=[1,2,3,4]
	delete a[1]
	console.log(a)
	b.splice(1,1)
	console.log(b)
    var c=[1,2,3,4]
    this.$delete(c,1)
    console.log(c)
</script>

Result:

##$remove

    this.a = [&#39;222&#39;,&#39;333&#39;];
    this.a.$remove(&#39;222&#39;);

Related recommendations :《

vue.js tutorial

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