In jquery, traversal is used more often in the case of processing JSON arrays, but it doesn't seem too much to use adding to remove these.
Today, I tried json[i].remove() and json.remove(i) and then didn't work. It seems that the JSON data in the DOM object of the web page appears in the form of an array. I checked the operation of the array in the related JS and tried it out.
Record it.
1. Creation of arrays
The code copy is as follows:
var arrayObj = new Array(); //Create an array
var arrayObj = new Array([size]); //Create an array and specify the length, note that it is not the upper limit, it 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 that specifies the length, in fact, the array is longer in all cases, that is, even if the length is specified, the element can still be stored outside the specified length. Note: the length will change accordingly.
2. Access to elements of array
The code copy is as follows:
var testGetArrValue=arrayObj[1]; //Get the element value of the array
arrayObj[1]= "This is a new value"; // Assign a new value to the array element
3. Adding array elements
The code copy is as follows:
arrayObj. 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 array to start, and the elements in the array will automatically move backwards, returning the new length of the array
arrayObj.splice(insertPos,0,[item1[, item2[, . . . [,itemN]]]]);//Insert one or more new elements into the specified position of the array, the elements at the insertion position will automatically move backwards, and return "".
4. Deletion of array elements
The code copy is as follows:
arrayObj.pop(); //Remove the last element and return the value of the element
arrayObj.shift(); //Remove the last element and return the element value, the elements in the array will automatically move forward.
arrayObj.splice(deletePos,deleteCount); //Delete the element of the specified number of deleteCount starting from the specified position deletePos, and return the removed element in the array form.
5. Intercept and merge of arrays
The code copy is as follows:
arrayObj.slice(start, [end]); //Return part of the array in the form of an array, note that the elements corresponding to end are not included. If end is omitted, all elements after start will be copied
arrayObj.concat([item1[, item2[, . . . [,itemN]]]]); //Connect multiple arrays (can also be strings, or a mixture of arrays and strings) into an array, and return the connected new array
6. Copy of array
The code copy is as follows:
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. Sort array elements
The code copy is as follows:
arrayObj.reverse(); //Reverse the element (the first one is ranked last, the last one is ranked first), and return the array address
arrayObj.sort(); //Sort array elements and return array address
8. Stringing of array elements
The code copy is as follows:
arrayObj.join(separator); //Returns a string, which joins each element value of the array together, separated by a separator.
toLocaleString , toString , valueOf: It can be regarded as a special usage of join, not often used