Arrays Array
Arr.tostring () converts an array to a string, with each item separated by commas
Value. of returns the array object itself
The use of slice
var arr1=arr.slice (1,-1); The second is a negative number, which is equivalent to the second number is the second length+.
var arr1=arr.slice (1,0); The second number is 0,
arr1=0; var arr1=arr.slice (1,3); The subscript in the array is the number of 1-2 to Arr1,arr unchanged.
var arr1=arr.slice (1); arr1= Subscript 1 starts to the last array, arr does not change
var arr1=arr.slice (1,3,7); The subscript in the array is the number of 1-2 to Arr1,arr unchanged.
The use of Splic
var arr2=arr.splice (1,5); Arr2= 5 Items starting from subscript 1, arr varies
var arr2=arr.splice (1); arr2= Subscript 1 starts to the last array, arr changes
var arr2=arr.splice (n/a); Arr2= from the following two items starting with subscript 1, arr=3 replaced by the 2 items in the original array starting with subscript 1.
var arr2=arr.splice (1,5); Arr2= 5 Items starting from subscript 1, arr varies
var arr2=arr.splice (1); arr2= Subscript 1 starts to the last array, arr changes
var arr2=arr.splice (n/a); Arr2= from the following two items starting with subscript 1, arr=3 replaced by the 2 items in the original array starting with subscript 1.
var arr2=arr.splice (1,3, "a", "B", "C"); Arr2= from the following two items starting with subscript 1, arr= "A", "B", "C" to the beginning of subscript 1 in the original array after 2 items
Three ways to empty an array
var arr=[100,200,300];
Arr1=arr.splice (0,arr.length);
Console.log (arr);
var arr=[];
Console.log (arr);
arr.length=0;
Console.log (arr);
Array sorting:
Arr.reverse () Reverses the elements in the array
Arr.sort () Sorts the elements in the array
Array iterations:
Filter () returns true to leave and returns false for discard
The ForEach () loop iterates through each item of an array, iterating through each item in the output array and the index of each item
Manipulating arrays:
Join () joins the elements in the array into a string output
Concat () Connect two arrays
Strings string
String can be seen as an array of characters, so he also has length
Spilt is a character in a string that splits an element in an array by a character, that is, a string can be converted to an array
Str.silt ("-") is cut into a number, using "-" to split the array, and if not-the array will be split with ""
Concat Connect two strings, you can consider a string as an array of single characters
Slice string usage in the same number of arrays
Slice string usage and substring usage are basically the same
var str4=str.slice (2,-2); Subscript position from the first digit to the second digit of the str.length+
var str5=str.substring (2,-2); Negative number equivalent to 0, equivalent to incoming (0,2)
var str6=str.substring (0); parameter is only one 0, output all
var str2=str.slice (2,6); Remove the value from 2 to 6, 6 cannot be taken
var str3=str.slice (-2); Pass in negative numbers, passing in the last two bits of the string
SUBSTR usage
var str1=str.substr (2,6); The second number is the number
var str1=str.substr ( -2); Intercept the last two digits
var str8=str.substr (0); Intercept all
var str9=str.substr (2,-4); The second digit is a negative number equivalent to 0, not intercepted, and the output is empty
Methods unique to Strings
CharAt: Gets the character of the specified index position in the string
charCodeAt: Gets the ASCII value of the character in the specified index position in the string
Convert case:
Convert str.touppercase () to uppercase
Convert str.tolocaleuppercase () to uppercase (local)
Convert str.tolowercase () to lowercase
Str.tolocalelowercase Convert to lowercase (local)
Trim (): Used to remove the space before and after the string, can only remove
Replace (): Replaces characters inside a string
You can replace the symbol or replace the character
var str= "AAABBBCCC";
Console.log (Str.replace ("A", "w")); The console output converts the a character to the W character, where only the first A is converted
Console.log (Str.replace (/a/g, "w")) note the format, G is global, here so a is converted to W
Custom Objects
Objects generally consist of two parts: Properties and Methods
Array and string APIs are used