In operation jquery json array (rpm)

More in the case of processing JSON array in jquery traversal used, but does not seem too much use to remove these add.

Today tried json [i] .remove (), will not work after json.remove (i), see page's DOM object like an array of JSON data is appearing, reviewed the operation in a try under the relevant array JS really cool.

record it.

1, create an array of

var arrayObj = new Array (); // create an array

var arrayObj = new Array ([size]); // create an array and specified length, attention is not the upper limit, the length

var arrayObj = new Array ([element0 [, element1 [, ... [, elementN]]]]); create an array and assign

    It is noted that, although the second method creates an array of specified length, but in fact an array of all cases are longer, which means that even if you specify a length of 5, can still be stored outside of the prescribed length of the element, Note: At this length will change.

2, the elements of the array access

var testGetArrValue = arrayObj [1]; // Get the value of the array element

arrayObj [1] = "This is the new value"; // new value given to the array elements

3, the array elements added - Stack Queue methods and methods

. arrayObj Push ([ITEM1 [ITEM2 [[itemN]]]...]);      // one or more new elements added sequentially from left to right to the end of the array, return the updated array length

arrayObj.unshift ([ITEM1 [ITEM2 [[itemN]]]...]);   // one or more new elements are sequentially added to the header, the array elements of the array in order to automatically move back from right to left returns a new array length

arrayObj.splice (insertPos, 0, [ITEM1 [, ITEM2 [, [, itemN]]]...]); // one or more new elements into the array of the specified position, the insertion position of the element is automatically moved back ,return""

4, delete the array elements - stacks and queues method method

arrayObj.pop ();     // removes the last element and returns the trailing elements, update of the array length

arrayObj.shift ();    // remove a forwardmost element and header and returns an array of elements, update of the array length

arrayObj.splice (deletePos, deleteCount); // delete the specified number deleteCount starting at the specified location deletePos elements, returns an array of elements removed

5, and the merge array interception

arrayObj.slice (start, [end]); // return a portion of the array as an array of elements corresponding end note does not include all of the elements will be omitted if after the copy start end

arrayObj.concat ([ITEM1 [, ITEM2 [, [, itemN]]]...]); // plurality of arrays (or a string, array and string or mixed) is connected to an array, good new array return connection

6, copies of the array

arrayObj.slice (0); // returns a copy of an array of the array, a new array is noted, not directed

arrayObj.concat (); // returns a copy of an array of the array, a new array is noted, not directed

7, sort the array elements

arrayObj.reverse (); // reversing elements (most discharged before the end of the last routed foremost), returns an array of address

arrayObj.sort ();       // the elements in the array in ASCII characters (all as a string) in ascending order, the return address of the array

8, a string of array elements

arrayObj.join (separator); // return a string, the string value of each element of the array are connected together, separated by separator.

toLocaleString, toString, valueOf: can be seen as a special usage join, and not commonly used

9, splice () method of operation

  •  (1) delete operations: splice (sIndex, len): wherein sindex as a starting position, len is the length of the array, taken, for example:
 var removed = array.splice(1,3);
 alert(removed);//["red", "orange", "gray"]
 alert(array);//["black", "green"]
     Obviously, there are deleted items, returns a new array consisting of these deleted items. (Original array to retain deleted section)
  •  (2) inserting operation: splice (rIndex, 0, args ...): wherein rindex position is to be inserted, args for the element to replace, for example:
 = Array.splice removed (. 1, 0, "Yellow");
 IF (removed.length == 0) {
  Alert ( "This is an empty array objects");
 }
 Alert (Array); // [ "Black" , "yellow", "green" ]
    Seen from the above example, when there is no delete key, it returns an empty array of objects. And inserting a plurality of elements, the array elements which rIndex position and the rear position to the rearward movement of the array sequentially.
  • (3) replace operation: splice (sIndex, len, args ...): First, the position and the subsequent Delete sindex len elements, and then from the args sindex starting position by one insert operation, for example:
 removed = array.splice(1, 2, "orange");
 alert(array);//["black", "orange"]
 alert(removed);//["yellow", "green"]

Reprinted from: http: //www.cnblogs.com/hrh0627/archive/2011/01/07/1930424.html

Reproduced in: https: //www.cnblogs.com/JoannaQ/p/3436685.html

Guess you like

Origin blog.csdn.net/weixin_33937499/article/details/93056929