SoFunction
Updated on 2025-02-28

Summary of commonly used API functions for JavaScript string objects (connection, replacement, segmentation, conversion, etc.)

This article describes the commonly used API functions of JavaScript string objects. Share it for your reference, as follows:

1. concat(str1,str2,···)

Connection string

2. indexOf(str,start)

Returns where str first appears in the string

var str = "hello world";
("hello"); // 0
("o",5); // 7
("World"); // -1

3. lastIndexOf(str,start)

Returns the last location of str in the string

var str = "hello world";
("hello"); // 0
("o",3); // -1
("o",5); // 4

4. replace(regexp/substr,replacement)

Replace other characters with some characters in a string, or replace a string that matches the regular

var str = "I is Allen.";
("is","am"); // "I am Allen."


5. slice(start,end)

Returns a fragment of a string

var str = "I am Jack.";
(3,7); // "m Ja"
(3); // "m Jack."
(3,-3); // "m Ja"

6. split(separator,limit)

Split a string into a substring and return the result as a string array

var str = "hello world";
(" "); // ["hello","world"]
(" ",1); // ["hello"]

7. substr(start,lenght)

Returns a string of specified length starting from the specified position

var str = "how do you do?";
(4,2); // "do"
(4); // "do you do?"
(4,0); // " "
(4,-1); // " "
(-3); // "do?"

8. substring(start,end)

Returns a string at the specified position in the string object, containing the character at start, but not the character at end

var str = "how do you do?";
(0,3); // "how"

9. toLowerCase()

Convert string to lowercase

10. toUpperCase()

Convert string to uppercase

var str = "How do you do?";
(); // "how do you do?"
(); // "HOW DO YOU DO?"

For more information about JavaScript, readers who are interested in reading this site's special topic:Summary of json operation skills in JavaScript》、《Summary of JavaScript switching effects and techniques》、《Summary of JavaScript search algorithm skills》、《Summary of JavaScript animation special effects and techniques》、《Summary of JavaScript Errors and Debugging Skills》、《Summary of JavaScript data structure and algorithm techniques》、《JavaScript traversal algorithm and skills summary"and"Summary of JavaScript mathematical operations usage

I hope this article will be helpful to everyone's JavaScript programming.