This is the second day of my participation in the August Text Challenge.More challenges in August
Creating a string
Literal creation method
Var STR = 'string' console.log(STR) // StringCopy the code
String object creation method
Var STR = new String(' String ') console.log(STR) // StringCopy the code
Lookup class method
- charAt(index) - Parameter - index: 0 ~ lengrh-1 value, default is 0, beyond returns an empty string - returns a character at a specific position - charCodeAt(index) - parameter - index: - fromCharCode(num1,num2...) - fromCharCode(num1,num2...) - Parameter - Can fill in more than one Unicode encoding - Returns the character corresponding to the specified Unicode encoding - indexOf(searchValue [,fromIndex]) - parameter - searchValue: Find the value - fromIndex: If the value is greater than length, return -1 - returns the index of the first specified value found. If no value is found, return -1. This method is case-sensitive -lastIndexof (searchValue [,fromIndex]) -parameter -searchValue: the value to be searched -fromindex: Specifies where to start the search. The default value is length, 0 if it is negative, or length if it is greater than length - returns the index of the last specified value found, or -1 if none was found, looking backwardsCopy the code
Intercepting class methods
-slice (begin[, end]) -parameter -begin: extracts characters from the index, if negative (if negative exceeds lenth, the default is 0), then extracts characters from right to left. -end: The end of the interception, if the argument is omitted, defaults to the last bit of the string. If it is a negative number, look for the last character position from right to left as well. Note that begin is included in the string in the screenshot and end does not contain ** the empty string is returned if the maximum index value is exceeded, or if the corresponding index of ends is before the begin index. -substr (start[, -start: start to extract the position of the string, if it is a negative number, search the string from right to left. -length: - Characters from the specified position are returned. Characters from the specified position to the specified number of characters are not recommended and may be removed in the future. - substring(begin[, end]) - parameter - begin: indicates the start position of the truncated index. - end: truncated end index position. Characters at this position are not included in the truncated range and are equal to length if greater than length. - Returns the character between two specified subscripts in the stringCopy the code
Other Common methods
-split (separator[, num]) -parameter -separator: Decide the separator character -num: Number of delimiters - To split strings into arrays of strings - concat (inferior to +, +=) - to merge one or more strings with the original string, And returns the new string - toLowerCase() - converts the string toLowerCase and returns the new string - toUpperCase() - converts the string toUpperCase and returns the new string - trim() - removes leading and trailing whitespaceCopy the code