1. What are the attributes and methods of the string Array Date Math built-in object? Answer: ① String attributes: length method for obtaining the length of a String: indexOf () returns an integer from left to right to retrieve the substring at the first position of the original String, if the start position of the String in the String object cannot be found, return-1 Example: var a = 'abc'; alert (. indexOf ('B'); // return value 1 returns the value that the index of B at the index position of string a starts from 0. indexOf ('bf'); // no result is found.-1 lastIndexOf () is returned to retrieve the substring from right to left. Example: var B = 'abcde '; alert (. lastIndexOf ('D'); // return value 3 returns the index of d starting from 0 at the position of B string index. lastIndexOf ('bf'); // No-1 ------------------ returned ------------------ ------------------------------------------------------- Usage: object. if indexOf () has no parameter, return value-1 object. when lastIndexOf () does not have a parameter, the return value-1 is returned by the number of index subscripts ------------------------------------------------------------ usage: Regular Expression search symbols/search content/search () returns the location where the content searched by the regular expression matches the first string. Example: var str = "Visit W3School! "Document. write (str. search (/W3School/) Outputs 6 documents. write (str. search (/w3school/) Output-1 case sensitive document. write (str. search (/w3school/I) Output 6 I in the regular expression indicates that the return value is 'null' when there is a parameter, it is returned by the number of index subscripts () use the regular expression mode to search for the string and use the result as an array. Return example: var str = "Hello world! "Document. write (str. match ("world") + "<br/>") // worlddocument. write (str. match ("World") + "<br/>") // nulldocument. write (str. match ("worlld") + "<br/>") // nulldocument. write (str. match ("world! ") // World! In this example, we use a globally matched regular expression to retrieve all numbers in the string: var str = "1 plus 2 equal 3" document. write (str. match (/\ d +/g) g in the regular expression that match multiple times without g only returns match once result output: 1, 2, 3 then substr () method to extract a specified number of characters starting from the start subscript from a string. The start parameter description is required for the syntax stringObject. substr (start, length. The starting subscript of the substring to be extracted. It must be a numerical value. If it is a negative number, this parameter declares the position starting from the end of the string. That is to say,-1 refers to the last character in the string,-2 refers to the second to last character, and so on. Length is optional. The number of characters in the substring. It must be a numerical value. If this parameter is omitted, the string from the start position of the stringObject to the end is returned. Return a new string containing the length starting from the start of the stringObject (including the characters indicated by start. If length is not specified, the returned string contains characters from start to the end of stringObject. Note: The substr () parameter specifies the starting position and length of the substring. Therefore, it can be used instead of substring () and slice. Important: ECMAscript does not standardize this method, so it is opposed to using it. Important: in IE 4, the value of start is invalid. In this BUG, start specifies the position of 0th characters. This BUG has been fixed in later versions. Example 1 in this example, we use substr () to extract some characters from the string: <script type = "text/javascript"> var str = "Hello world! "Document. write (str. substr (3) </script> output: lo world! Example 2 in this example, we use substr () to extract some characters from the string: <script type = "text/javascript"> var str = "Hello world! "Document. write (str. substr (3, 7) </script> output: lo worl evaluate definition and usage the substring () method is used to extract the character string that is intermediary between two specified subscripts. The start parameter description is required for the syntax stringObject. substring (start, stop. A non-negative integer that specifies the position of the first character of the substring to be extracted in the stringObject. Optional. A non-negative integer is 1 more than the position of the last character of the substring to be extracted in the stringObject. If this parameter is omitted, the returned substring ends at the end of the string. Return a new string. The value of this string contains a substring of stringObject. Its content is all characters from start to stop-1, and its length is stop minus start. It indicates that the substring returned by the substring () method includes the character at start, but not the character at stop. If the start parameter is the same as the stop parameter, this method returns an empty string (a string with a length of 0 ). If start is greater than stop, the two parameters are exchanged before the method extracts the substring. Tips and notes: Unlike slice () and substr (), substring () does not accept negative parameters. Example 1 in this example, we use substring () to extract some characters from the string: <script type = "text/javascript"> var str = "Hello world! "Document. write (str. substring (3) </script> output: lo world! In this example, we will use substring () to extract some characters from the string: <script type = "text/javascript"> var str = "Hello world! "Document. write (str. substring (3, 7) </script> output: lo w evaluate defines and uses the concat () method to connect two or more arrays. This method does not change the existing array, but only returns a copy of the connected array. The arrayObject. concat (arrayX, arrayX,..., arrayX) parameter description is required for arrayX. This parameter can be a specific value or an array object. It can be any number. Returns a new array. This array is generated by adding all arrayX parameters to arrayObject. If the concat () operation parameter is an array, the elements in the array are added instead of an array. Example 1 in this example, we will connect the parameters in concat () to array a: <script type = "text/javascript"> var a = [, 3]; document. write (. concat (); </script> output:, 5 example 2 in this example, we create two arrays and connect them using concat: <script type = "text/javascript"> var arr = new Array (3) arr [0] = "George" arr [1] = "John" arr [2] = "Thomas" var arr2 = new Array (3) arr2 [0] = "James" arr2 [1] = "Adrew" arr2 [2] = "Martin" document. write (arr. concat (arr2) </SC Ript> output: George, John, Thomas, James, Adrew, Martin Example 3 in this example, we create three arrays and connect them using concat: <script type = "text/javascript"> var arr = new Array (3) arr [0] = "George" arr [1] = "John" arr [2] = "Thomas" var arr2 = new Array (3) arr2 [0] = "James" arr2 [1] = "Adrew" arr2 [2] = "Martin" var arr3 = new Array (2) arr3 [0] = "William" arr3 [1] = "Franklin" document. write (arr. concat (arr2, arr3) </script> output: George, John, Thomas, James, Adrew, Martin, William, Franklin ---------------------------------------------------------------------- the split () method is used to split a string into a string array. The parameter description of the stringObject. split (separator, howator) is required. String or regular expression, which separates stringObject from the specified place. Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings are returned than the array specified by this parameter. If this parameter is not set, the entire string is split, regardless of its length. Returns a string array. This array is created by dividing the string stringObject into substrings at the boundary specified by separator. The strings in the returned array do not include the separator itself. However, if separator is a regular expression that contains a subexpression, the returned array contains the strings that match the subexpression (but does not include the text that matches the entire regular expression ). Note: If the empty string ("") is used as a separator, each character in the stringObject is separated. Note: The operations executed by String. split () are the opposite to those executed by Array. join. Instance example 1 in this example, we will split the string in different ways: <script type = "text/javascript"> var str = "How are you doing today? "Document. write (str. split ("") + "<br/>") document. write (str. split ("") + "<br/>") document. write (str. split ("", 3) </script> output: How, are, you, doing, today? H, o, w, a, r, e, y, o, u, d, o, I, n, g, t, o, d,, y ,? How, are, you example 2 in this example, we will split the string with a more complex structure: "2: 3: 4: 5 ". split (":") // Returns ["2", "3", "4", "5"] "| a | B | c ". split ("|") // Returns ["", "a", "B", "c"] example 3. Use the following code to separate sentences into words: var words = sentence. split ('') or use a regular expression as separator: var words = sentence. split (/\ s +/) Example 4 if you want to split words into letters or strings into characters, use the following code: "hello ". split ("") // Returns ["h", "e", "l", "l", "o, please use the howmany parameter: "hello ". split ("", 3) // you can return ["h", "e", "l"] replace () to replace the string and then copy the new string. Example: var a = 'abc'; alert (. replace ('C', '123') Output: The ab123 character toUpperCase () method is used to convert a string to uppercase var str = 'abc'; document. write (str. toUpperCase () Output: The ABC encode toLowerCase () method is used to convert a string to lowercase var str = 'abcdef'; document. write (str. toLowerCase () Output: abcdef success ------------------------------------------------------------------------------------------------