
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Name some of the string methods in javascript?
The String object lets you work with a series of characters; it wraps Javascript's string primitive data type with a number of helper methods. As JavaScript automatically converts between string primitives and String objects, you can call any of the helper methods of the String object on a string primitive.
Following are some of the methods available for strings in JavaScript −
concat() −Combines the text of two strings and returns a new string.
indexOf() −Returns the index within the calling String object of the first occurrence of the specified value, or -1 if not found.
lastIndexOf() −Returns the index within the calling String object of the last occurrence of the specified value, or -1 if not found.
match() −Used to match a regular expression against a string.
replace() −Used to find a match between a regular expression and a string, and to replace the matched substring with a new substring.
search() −Executes the search for a match between a regular expression and a specified string.
slice() −Extracts a section of a string and returns a new string.
split() −Splits a String object into an array of strings by separating the string into substrings.
substr() −Returns the characters in a string beginning at the specified location through the specified number of characters.
substring() −Returns the characters in a string between two indexes into the string.
toLowerCase() −Returns the calling string value converted to lower case.
toUpperCase() −Returns the calling string value converted to uppercase.
valueOf() −Returns the primitive value of the specified object.
Usage of some of these methods
let a = "Hello World!"; console.log(a.concat(" test")) console.log(a.indexOf("l")) console.log(a.lastIndexOf("l")) console.log(a.replace("Hello", "Hi")) console.log(a.substr(3, 7)) console.log(a.toUpperCase())
Output
Hello World! test 2 9 Hi World! lo Worl HELLO WORLD!
- Related Questions & Answers
- Name some methods of weakMap instances in javascript?
- What are some of the commonly used methods of the array class in C#?
- Check whether a string ends with some other string - JavaScript
- Check if a string is the typed name of the given name in Python
- What is the usage of some() method in JavaScript?
- C# String Methods
- Python String Methods ?
- Java String Methods
- How to get the code name and product name of the browser in JavaScript?
- Get global variable dynamically by name string in JavaScript?
- Reverse digits of an integer in JavaScript without using array or string methods
- What are some free domain name suggester tools?
- String Methods in Dart Programming
- What are the methods of a boolean object in JavaScript?
- What are the methods of an array object in JavaScript?