Home > Web Front-end > JS Tutorial > Detailed explanation of the difference between delete element and splice element in js

Detailed explanation of the difference between delete element and splice element in js

小云云
Release: 2018-02-05 09:49:29
Original
1425 people have browsed it

This article mainly shares with you the detailed explanation of the difference between delete and splice when deleting elements in js arrays. It has a good reference value and I hope it will be helpful to everyone. Let’s follow the editor to take a look, I hope it can help everyone.

For example, there is an array: var textArr = ['a','b','c','d'];

At this time I want to delete this array The b element:

Method 1: delete delete array

##delete textArr[1] The result is: ["a",undefined," c","d"]

Only the deleted element becomes undefined, and the key values ​​of other elements remain unchanged.

Method 2: aplice deletes the array

splice(index,len,[item])

Comment: This method will change the original array.

index:Start index of array                                                                                                                                    #Replacement value, if the deletion operation occurs, the item will be empty

textArr.splice(1,1); The result is: ["a", "c", "d"] Directly deleting the array changes the array value.

Related recommendations:

What are the delete and delete operators in js? And usage example analysis

Talk about the example tutorial of DELETE syntax


Recommended articles about the php ftp_delete() function

The above is the detailed content of Detailed explanation of the difference between delete element and splice element in js. 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