First, add a splice function:Splice: This method is used to delete an element from the array.Array. splice (index, count, value ....);Index: indicates which subscript starts,Count: number of elements deletedValue: indicates the added element.Example:
I believe that many people who learn the JavaScript language will often be confused about the slice and splice methods. Although they have similar names, they have completely different functions. So this article will give you a detailed review of
POP deletes last item
Deletes the last item and returns the value of the deleted element, or returns Undefine if the array is empty
var a = [1,2,3,4,5];
A.pop ();//a:[1, 2, 3, 4]
a.pop ();//a:[1, 2, 3]
Shift deletes the first item
When writing JS code, we often use the splice function to delete elements in the array, because the splice function modifies the arrays directly, eliminating the need to write an algorithm to move the other elements of the array to the deleted
Objective
Today I revisit the JavaScript, see the array method, there are two of the more similar methods--splice and splice, look like, is more than one P, but the usage is quite different.
In use, you can reduce confusion by selecting an API
Js ---- splice for Array Processing (with the js original addClass method), js ---- addclass
Last time I wrote a carousel method: http://blog.csdn.net/stronglyh/article/details/46833499
When someone asked me, they gave me html, so I saw jquery
First add a splice function:
Splice: The purpose of this method is to remove an element from an array
Array.splice (Index,count,value ...);
Index: Indicates from which subscript to start,
Count: Indicates the number of deleted elements
Value:
Splice in JavaScript is mainly used to operate arrays in js, including deleting, adding, and replacing arrays. This article describes the detailed usage of the splice method in JavaScript. For more information, see splice in JavaScript. It is mainly
Copy codeThe Code is as follows:Array. prototype. ArrayInsertAfter = function (Num, obj){Var tempArr = new Array ();Var l = this. length;For (var I = 0; I {TempArr. push (this. shift ());}L = tempArr. length;For (var I = 0; I {This. push (tempArr.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.