1, usually we will use the way to insert data into the array is push, it is also used, but it should be noted that the push method has a return value.
var arr = [1,2,3];alert (Arr.push ('aaaaaa' ) ) //The Push method returns the array length of alert (arr); Alert (Arr.unshift ('bbbbb')); // push is inserted backwards, and unshift is inserted forward, it is understood to hold down the head forward insertion, homophonic (convenient memory). The return value is also the array length alert (arr); // It is worth noting that IE6, IE7 is not support unshift return value, but return underfined.
2.
var arr = ['aa','bb','cc' ];alert (Arr.pop ()); // Delete the last array, the return value is deleted. Pop homophonic Cindy Managed, put a fart back. (easy memory)alert (arr); alert (Arr.shift ()); // Delete the first of the array, the return value is deleted. alert (arr);
3, the use of four methods, you can do the array content "transposition Walk"
varARR1 = ['AA','BB','cc','DD'];arr1.unshift (Arr1.pop ()); //results: DD,AA,BB,CCalert (arr1);varARR2 = ['AA','BB','cc','DD'];arr2.push (Arr2.shift ()); //results: Bb,cc,dd,aaalert (ARR2);
Methods of Arrays (i)