0% found this document useful (0 votes)
5 views2 pages

JavaScript_String_Functions_Clean

The document provides an overview of JavaScript string functions, categorized into basic string methods, searching, trimming and modifying, slicing and splitting, testing and matching, and other useful methods. Each category includes specific functions along with their descriptions, such as 'length', 'includes', 'trim', 'slice', and 'repeat'. This serves as a reference for developers to utilize string manipulation techniques in JavaScript.

Uploaded by

Sachin Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

JavaScript_String_Functions_Clean

The document provides an overview of JavaScript string functions, categorized into basic string methods, searching, trimming and modifying, slicing and splitting, testing and matching, and other useful methods. Each category includes specific functions along with their descriptions, such as 'length', 'includes', 'trim', 'slice', and 'repeat'. This serves as a reference for developers to utilize string manipulation techniques in JavaScript.

Uploaded by

Sachin Jadhav
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JavaScript String Functions

Basic String Methods


Function Description
length Returns the length of the string.
charAt(index) Returns the character at the specified index.
charCodeAt(index) Returns the Unicode value of the character at the specified index.
concat(str1, str2, ...) Joins two or more strings.

Searching
Function Description
includes(substring) Checks if the string contains the specified substring.
indexOf(substring) Returns the index of the first occurrence (or -1 if not found).
lastIndexOf(substring) Returns the index of the last occurrence.
startsWith(substring) Checks if the string starts with the given substring.
endsWith(substring) Checks if the string ends with the given substring.

Trimming and Modifying


Function Description
trim() Removes whitespace from both ends.
trimStart() / trimEnd() Removes whitespace from the start or end.
toUpperCase() Converts to uppercase.
toLowerCase() Converts to lowercase.
replace(search, replacement) Replaces a substring or pattern with something else.
replaceAll(search, replacement)Replaces all occurrences of a substring. (ES2021+)

Slicing and Splitting


Function Description
slice(start, end) Extracts a section of a string.
substring(start, end) Similar to slice but doesn't accept negative indexes.
substr(start, length) Extracts a substring of a given length (deprecated).
split(separator) Splits a string into an array based on a delimiter.

Testing and Matching


Function Description
match(regex) Matches a string against a regular expression.
matchAll(regex) Returns all matches with capturing groups. (ES2020+)
search(regex) Searches for a match using a regex and returns the index.

Other Useful Methods


Function Description
repeat(n) Repeats the string n times.
padStart(length, padString) Pads the start of a string.
padEnd(length, padString) Pads the end of a string.
localeCompare(otherString) Compares two strings based on locale.

You might also like