Addition, deletion and modification of json array
operations
in
jquery is the length
var arrayObj = new Array([element0[, element1[, ...[, elementN]]]]); Create an array and assign a value It
should be noted that although the second method creates an array with a specified length, the actual In all the above cases, the array is variable-length, that is to say, even if the specified length is 5, elements can still be stored outside the specified length. Note: the length will change accordingly.
2. Access to the elements of the array
var testGetArrValue=arrayObj[1]; //Get the element value of the array
arrayObj[1]= "This is the new value"; //Give a new value to the array element
3. Add
arrayObj to the array element .push([item1 [item2 [. . . [itemN ]]]]);// Add one or more new elements to the end of the array and return the new length of the array
arrayObj.unshift([item1 [item2 [. . . [itemN ]]]]);// Add one or more new elements to the beginning of the array, the elements in the array are automatically moved backward, and the new length of the array is returned
arrayObj.splice(insertPos,0,[item1[, item2[, . . . [,itemN]]]]);//Insert one or more new elements into the specified position of the array, the element at the insertion position is automatically moved backward, and returns "".
4. Deletion of array elements
arrayObj.pop(); //Remove the last element and return the value of the element
arrayObj.shift(); //Remove the first element and return the value of the element, the elements in the array are automatically moved forward
arrayObj
/ _
_ /Return part of the array in the form of an array. Note that the element corresponding to end is not included. If end is omitted, all elements after start will be copied
arrayObj.concat([item1[, item2[, . . . [,itemN]]]]]) ; //Concatenate multiple arrays (or strings, or a mixture of arrays and strings) into an array, return the new concatenated array
6, a copy of the array
arrayObj.slice(0); //Return The copy array of the array, note that it is a new array, not pointing to
arrayObj.concat(); //Return the copy array of the array, note that it is a new array, not pointing to
7, the sorting of array elements
arrayObj.reverse(); / /Reverse the elements (the first row to the last, the last row to the first), return the array address
arrayObj.sort(); // Sort the array elements, return the array address
8, the stringification of the array elements
arrayObj.join(separator); //Return a string that joins the values of each element of the array, separated by a separator.
toLocaleString , toString , valueOf: It can be regarded as a special usage of join, which is not commonly used.
From :
http://www.cnblogs.com/divenswu/p/3768127.html
Operation addition, deletion and modification of json array in jquery
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327072235&siteId=291194637
Recommended
Ranking