JS Self-band function
Concat
Combines text of two or more characters to return a new string.
var a = "Hello";
var B = ", World";
var C = A.concat (b);
alert (c);
c = "Hello,world"
IndexOf
Returns the index (from left to right) of the first occurrence of a substring in a string. If there is no match, returns-1.
var index1 = A.indexof ("L");
INDEX1 = 2
var index2 = A.indexof ("L", 3);
INDEX2 = 3
CharAt
Returns the character at the specified position.
var Get_char = A.charat (0);
Get_char = "H"
LastIndexOf
Returns the index (right-to-left search) at the last occurrence of a substring in a string, or 1 if there are no matches.
var index1 = lastIndexOf (' l ');
INDEX1 = 3
var index2 = lastIndexOf (' l ', 2)
Index2 = 2
Match
Checks if a string matches the contents of a regular expression, and returns null if there is a match.
var re = new RegExp (/^/w+$/);
var is_alpha1 = A.match (re);
IS_ALPHA1 = "Hello"
var is_alpha2 = B.match (re);
IS_ALPHA2 = null
Substring
Returns a substring of a string in which the incoming parameter is the starting and ending position.
var sub_string1 = a.substring (1);
Sub_string1 = "Ello"
var sub_string2 = a.substring (1,4);
Sub_string2 = "ell"
Substr
Returns a substring of a string in which the incoming parameter is the starting position and length
var sub_string1 = a.substr (1);
Sub_string1 = "Ello"
var sub_string2 = a.substr (1,4);
Sub_string2 = "Ello"
Replace
Used to find a string that matches a regular expression, and then use the new string instead of the matching string.
var result1 = A.replace (Re, "Hello");
RESULT1 = "Hello"
var result2 = B.replace (Re, "Hello");
RESULT2 = ", World"
Search
Performs a regular expression matching lookup. If the lookup succeeds, returns the matching index value in the string. otherwise returns-1.
var index1 = A.search (re);
index1 = 0
var index2 = B.search (re);
Index2 =-1
Slice
Extracts part of a string and returns a new string (same as substring).
var sub_string1 = A.slice (1);
Sub_string1 = "Ello"
var sub_string2 = A.slice (1,4);
Sub_string2 = "ell"
Split
A string is made into a string array by dividing the string into substrings.
var arr1 = A.split ("");
ARR1 = [H,e,l,l,o]
Length
Returns the length of a string, which refers to the number of characters it contains.
var len = A.length ();
Len = 5
toLowerCase
Turns the entire string into lowercase letters.
var lower_string = A.tolowercase ();
lower_string = "Hello"
toUpperCase
Turns the entire string into uppercase.
var upper_string = A.touppercase ();
upper_string = "HELLO"
JavaScript String Functions Daquan