1,. length----get array lengths;
var arr = [1,2,3,4,5];console.log(arr.length) //5
2, Shift ()----Delete the original array of the first item, and return the value of the deleted element, if the array is empty, return undefined, directly on the meta-array modification;
var arr= [1,2,3,4,5];var result = arr.shift(); console.log(arr) //[2,3,4,5]console.log(result) //1
3, Unshift ()----Add parameters to the beginning of the original array, and return the length of the array, directly on the meta-array modification;
arr = [1,2,3,4,5];result = arr.unshift(-2,-1);
Console.log (arr)//[-2,-1,1,2,3,4,5]
Console.log (Result)//7
4, pop ()----Delete the last item of the original array, and return the value of the deleted element, if the array is empty, return undefined, modify directly on the meta-array;
arr= [1,2,3,4,5];
result = Arr.pop ();
Console.log (arr)//[1,2,3,4]
Console.log (Result)//5
5, push ()----add parameters to the end of the original array, and return the length of the array, directly on the meta-array modification;
arr = [1,2,3,4,5];
result = Arr.push (6,7);
Console.log (arr)//[1,2,3,4,5,6,7]
Console.log (Result)//7
6, concat ()----array merge, return a new array, does not affect the original array;
arr = [1,2,3,4,5];
result = Arr.concat (6,7);
Console.log (arr); [1,2,3,4,5]
Console.log (result); [1,2,3,4,5,6,7]
7, sort ()----the array from small to large, directly on the original array modified;
arr = [4,5,2,3,1];result = arr.sort(); console.log(arr); //[1, 2, 3, 4, 5]console.log(result) //[1, 2, 3, 4, 5]
8, reverse ()----the inverse of the array, directly on the original array modified;
arr = [4,5,2,3,1];result = arr.reverse()console.log(arr); //[1, 3, 2, 5, 4]console.log(result) //[1, 3, 2, 5, 4]
9. Slice (startindex,endindex)----intercept the entry between the starting index StartIndex and the end index EndIndex to form a new array that includes the entry for the starting index StartIndex. Excludes items corresponding to the end index endindex;
arr = [1,2,3,4,5];result1 = arr.slice(2,5);result2 = arr.slice(2);console.log(arr) //[1,2,3,4,5]console.log(result1) //[3,4,5]console.log(result2) //[3,4,5]
10, join (separator)----Set the array of elements of a string, to separator as a delimiter, omit the words by default with a comma delimiter, does not affect the original array;
arr= [1,2,3,4,5];result = arr.join("|");console.log(arr) //[1, 2, 3, 4, 5]console.log(result) //1|2|3|4|5
11, Splice (Start,deletecount,val1,val2,...) ----Delete the DeleteCount item from the start position and insert the Val1,val2,... from that position, and modify it directly on the original array;
arr= [1,2,3,4,5];result1 = arr.splice(2,2,7,8,9);console.log(arr); //[1,2,7,8,9,5]console.log(result1); //[3,4]result2 = arr.splice(0,1); //同shiftconsole.log(arr); //[2,7,8,9,5]console.log(result2); //[1]arr.splice(0,0,-2,-1); //同unshiftconsole.log(arr); //[-2,-1,2,7,8,9,5]result3 = arr.length;console.log(result3); //7result4 = arr.splice(arr.length-1,1); //同popconsole.log(arr); //[-2,-1,2,7,8,9]console.log(result4); //[5]arr.splice(arr.length,0,6,7); //同pushconsole.log(arr); //[-2,-1,2,7,8,9,6,7]result5 = arr.length;console.log(result5) //8
Overview of the properties and methods contained in the JS array container