var t = [{' A ': 1}, {' A ': 2}, {' A ': 3}, {' A ': 4}];
T.push ({' A ': 5}); Add to
T[0].A = 11; Modify
T.splice (a); Delete
for (i = 0; i < t.length; i++)
alert (T[I].A);
The splice function alone can be used to increase, delete, change
Modify the operation:
var chaomao=[1,2,3,4,5]
Chaomao.splice (2,1,8,9) alert (Chaomao)//1,2,8,9,4,5
The first parameter is the array position of the prepare operation, the second parameter is the number of array items following the position of the operation, and the third one is after the replaced content
The example is: Starting with the Chaomao array position 2 (that is, the item with value 3, array subscript starting from 0), position 2 after the item, replace Chengcheng 8,9
If the second parameter is changed to 2, that is Chaomao.splice (2,2,8,9), that is, position 2 after the two items replaced by 8, 9, the result of printing is 1,2,8,9,5,3 and 4 of the 22 items have been replaced
It should be explained here that the number of items to be replaced is not necessarily equal to the number of items replaced, 1 items can be replaced by 3 items, 5 items can also be replaced by 2 items, and based on this principle, we use this method to add and delete operations to the array
Delete operation:
var chaomao=[1,2,3,4,5]
Chaomao.splice (2,1) alert (Chaomao)//1,2,4,5
In the above example, the position in the Chaomao 2 after the 1 items are replaced with empty, because there is no content, the result can be seen, the 3 is deleted
To add an action:
var chaomao=[1,2,3,4,5]
Chaomao.splice (2,0,8,9) alert (Chaomao)//1,2,8,9,3,4,5
In the above example, the 0 items in the Chaomao position 2 are replaced by 8, 9, which is equal to adding two
In fact, the delete and add operations are just two variants of the splice modification method.
jquery Operation JSON Array