Here’s what I think in order of frequency

1.substring()

The extract (string) method is used to extract characters between two specified subscripts.

let  a = "1, 2, 3";
document.write(a.substring(2,a.Length))
// The first argument starts with a character with subscript 0, including the current subscript 0,
// The second argument ends at a subscript of several, excluding the current subscript, which by default is +1 longer than the subscript position of the last character to be extracted in the string
 
// The total length is +1 from the second subscript, so the output is: 2,3
Copy the code

2.substr()

The extract () method extracts a specified number of characters from a string with a number of subscripts

var str="Hello!";
var n=str.substr(2.3)
// Extract three characters from the subscript 2, output llo
Copy the code

3.indexOf()

Method returns the first occurrence of a specified string value in a string, or -1 if no match is found

var str="runab site";
var n=str.indexOf("a");
// If only one parameter is specified, the string value to be retrieved will be returned with the specified subscript
// The second argument specifies where in the string to begin the search (including the input subscript), and returns the specified subscript upon query
// The output is: 3
Copy the code

4.lastIndexOf()

Method returns the last position of a specified string value, or -1 if no matching string is found

var str="runab site";
var n=str.lastIndexOf("a".3);
// if only one parameter is specified, the query will return the specified subscript
// The second argument moves forward from the character with the subscript (including the input subscript) to return the specified subscript
// The output is: 3
 
 
// Use with the above (return the last character)
let str= str.substring(0, str.lastIndexOf('e'));
Copy the code

5.replace()

The () method is used to replace some characters in a string with other characters, or to replace a substring that matches a regular expression.

var str="Hello, everyone!;
var n=str.replace("Big"."Small");
// The output result is: small family good!
 
 
// Can also be replaced with a re
var str="Everybody is so big.";
var n=str.replace(/ / g."Small");  //g is a global substitution
// The output result is: small home is so small
 
// Set the second argument to an empty deletable string
var str="Everybody is so big.";
var n=str.replace(/ / g."");  //g is a global substitution
// The output result is: good
 
Copy the code

Sometimes you have to concatenate the end of a character, you can do that

var str="hello world!"
var items=str.split("ll")      // ["he", "oWorld!"]
// Get an array of items that contains multiple strings separated by LL (not including LL)
var newStr=items.join("");       // heoWorld!
//join() concatenates arrays in arrays using empty strings into a new string, unquoted, comma delimited by default
Copy the code

Supplement:

  • The slice(start, end) method extracts a portion of a string and returns the extracted portion in a new string. Use the start (inclusive) and end (not included) arguments to specify what part of the string to extract, passing negative numbers from the back.
  • The includes() method is used to determine whether a string contains a specified substring, returning true if a match is found and false otherwise.
  • The search() method is used to retrieve a specified substring in a string, or to retrieve a substring that matches a regular expression.
  • The match() method retrieves a specified value within a string or finds a match for one or more regular expressions.
  • The test() method is used to retrieve the value specified in the string. Returns true or false.
  • The exec() method is used to retrieve a match for a regular expression in a string. Returns an array containing the matching results. If no match is found, the return value is null.
Male _ no. ❤ : Honest front end person, you can exchange and learn with your friends! Bloggers will do their best to help you!Copy the code