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 syntaxRecommended 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!