Do not change the original array:

  1. Concat () concatenates two or more arrays and returns the new array, leaving the original array unchanged
  2. Join () puts all the elements of an array into a string, converts the array to a string, does not change the array, and returns a string
  3. Slice (start,end) returns the selected elements from the existing array, extracts some elements, and puts them into the new array. 2: Truncated index of the end position, excluding the end index (default to last, also greater than array length). Returns a new array without changing the original array
  4. ToString () converts an array to a string, leaving the original array unchanged
  5. Map,filter,some,every, etc., do not change the original array

Change the original array:

  1. Pop () removes the last element of the array. If the array is empty, it does not change the array and returns undefined. It changes the array and returns the deleted element
  2. Shift () deletes the first element of the array, does nothing if the array is empty, returns undefined, changes the array, and returns the deleted element
  3. Push () adds one or more elements to the end of the array, changing the original array and returning the length of the new array
  4. Unshift () adds one or more elements to the beginning of the array, alters the original array, and returns the length of the new array
  5. Reverse () reverses the order of the elements in the array, changing the original array, and returning the array
  6. Sort () sorts the elements of the array, alters the original array, and returns the array
  7. Splice (start,length,item) Adds/removes items from an array, changes the original array, and returns an array of deleted elements

Difference between splice and slice:

  • Splice (I,j, “a”) deletes and adds elements. The splice() method is different from the slice() method, which modifies the array directly. Delete j (including I) from I and insert “A” at I.
  1. Delete – Used to delete elements with two arguments, the first argument (the location of the first item to be deleted) and the second argument (the number of items to be deleted)
  2. Insert – Inserts any element into the array at the specified location. Three arguments, the first argument (actual position), the second argument (0), and the third argument (inserted item)
  3. Replace – Inserts any element into the array at the specified location, and removes any number of items, three arguments. First argument (starting position), second argument (number of items deleted), third argument (insert any number of items)
var lang = ["111"."java"."javascript"];   
/ / delete
var removed = lang.splice(1.1);   
alert(lang); //111,javascript   
alert(removed); // Java, returns the deleted item
/ / insert
var insert = lang.splice(0.0."asp"); // Insert from position 0
alert(insert); / / return []
alert(lang); //["asp", "111", "java", "javascript"]   
/ / replace
var replace = lang.splice(1.1."c#"."ruby"); // Delete one item and insert two items
alert(lang); / / asp, c #, ruby and javascript
alert(replace); // return the deleted itemCopy the code
  • Slice (start,end) returns the selected element from an existing array, starting at the start bit and returning to end (including start but not end). If negative, it evaluates from the end of the array (again: Including start but not end), note that this method does not modify the array, but returns a subarray.