JavaScript array element deletion method delete and splice resolution

This article mainly introduces the JavaScaipt array element deletion method delete and splice parsing. In the paper, the presentation is very detailed in the document, which has a certain reference value for everyone’s learning or work. Friends needed to refer to

First, delete an element (less)

in Delete: Delete: Only deleted elements become undefined, ie array length unchanged

// Define array var ARRAY = [“AA”, “DD”, “CC”, “aa”]; // method 1: delete delete array elements delete array [1]; // Output: [“AA”, undefined, “cc”, “aa”]
   Output result: 

Second, the elements of the array
are described with SPLICE : This method automatically changes the original array, that is, each SPLICE (I, 1) array length is automatically reduced by 1

var array = [“aa”, “DD” , “cc”, “aa”]; // method 2: Delete array elements array.splice (1, 1); // output: [“AA”, “CC”, “aa”]

   AA CC AA 

The above is this article All content, I hope to learn from everyoneHelped, I also hope that everyone will support Tumi Clouds.
© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment