Home >Web Front-end >JS Tutorial >Personal summary of some properties and usage of String, Function, and Array_Basic knowledge

Personal summary of some properties and usage of String, Function, and Array_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 19:21:121010browse
Copy code The code is as follows:


/* Array */
Array.reverse()                                                                                                                                                                                                                        .
Array.sort()                                                                                                                                                                                                                                                     Sort the array into a new array.
s=Array.push("str1","str2") //Add the array from the back, s is the added record
s=Array.pop() //Delete the array from the back, s is the deleted record
s=Array.shift() //Delete the array from the front, s is the deleted record
s=Array.unshift("str1","str2") //Add the array from the front, s is the added record
s=Array.splice(3,2,"aa","bb") //Starting from the third end of the array, delete two arrays backwards and add a new array at that position. s is to add a record
s=Array.slice(2,4) //Start from the second to the fourth in the array, and the array itself has not changed.
s=Ar1.concat(Ar2) //Add array Ar2 to array Ar1 to generate a new array s.
s=Array.join("#") //Connect the array elements with # to form a string and return it to s.

/* Function */
Sample:function Test(arg1,arg2)
Use:Test("ddd", "sss", "fff")
//Test.arity :                          //The number of parameters set by the function (return value).
Test.length:                                     //The number of parameters set by the function (return value).
Test.caller: //Call Test() function (return function, IE supports).
Test.apply(obj, [arg1, arg2]) // Make the specified object (obj) have the properties and methods of Test.
Test.call(obj, arg1, arg2) // Make the specified object (obj) have the properties and methods of Test.
arguments:                                         //The actual number of parameters passed in (return array).
arguments.callee:                                                                                                                                                                           
(new Test).constructor:                                                                                                ​​​​​​​​​

/* String */
Str.slice(3,-5) //Start from the third string and get the value from the -5th (the fifth from the bottom. Parameters Two needs to be greater than parameter one, or negative).
Str.substring(3,6) //Start from the third string and get the value to the 6th one.
Str.substr(3,6) //Start from the end of the third string and take 6 characters backward.
Str.charCodeAt(4) //Returns the decimal code of the fifth string.
Str.charAt(4) //Returns the 5th string.
Str.toLowerCase() //Convert all characters to lowercase characters.
Str.toUpperCase() //Convert all characters to uppercase characters.
Str.split(",") //Use "," to split the string and return the array.
Str.search("aaa") //Find the position of aaa in the string, generally used with regular expressions.
Str.indexOf("aaa") //Find the position of aaa in the string.
Str.lastIndexOf("aaa") //Find the position where "aaa" appears in the string starting from the end.
Str.match("aaa") //Retrieve "aaa" from Str, return null or array, generally used with regular expressions.
Str.replace("aaa","bbb") //Replace the first "aaa" with "bbb", generally used with regular expressions.
String.fromCharCode(39080) //Returns a character generated by decimal encoding.
str1=str2.concat(str3) //Add str3 to str2 to generate a new string str1.



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn