Search Login
Daisy Rees
3 years ago Recommended
Learn JavaScript string functions How To Get The
Selected LI's Index
Learn about available JavaScript string functions. From An UL Using
Javascript [with
source code]
String Properties
10 months ago
[Link]
Learn How to Create
A WordPress
var str = "Jagathish"; Maintenance Mode
[Link]; //9 --> returns the length of the stri Page for Your
Website
10 months ago
Functions
The Repository for
1. `toUpperCase()` --> returns the new string in uppercase High Quality
TypeScript Type
format of source string
Definitions
10 months ago
var str = "Jagathish";
var str2 = [Link](); Build & Deploy A
YouTube Thumbnail
[Link](str);//Jagathish
Fetcher App with
[Link](str2);//JAGATHISH
React & TypeScript
Part 1 | Vite | Tailwind
CSS
2.`toLowerCase()` --> returns the new string in lowercase
9 months ago
format of source string
Responsive Login and
Registration Form in
var str = "Jagathish";
HTML CSS &
var str2 = [Link](); JavaScript
[Link](str);//Jagathish
8 months ago
[Link](str2);//jagathish
How to Build a
Chatbot Application
3.`trim()` --> returns a new string with removed white space with [Link]
from start and end of the string. 9 months ago
var str Search
= " Jagathish ";var trimmedStr = [Link]
Login
var trimmedStr1 = [Link]();
[Link](trimmedStr1); //"J aga"var str2 = "J
var trimmedStr2 = [Link]();
[Link](trimmedStr2); //"J ."
4.`trimStart()` --> returns a new string with removed white
space from start of the string. `trimLeft()` is an alias of this
method.
var str = " Jagathish ";
var trimmedStr = [Link]();
[Link](trimmedStr); //"Jagathish "
5.`trimEnd()` --> returns a new string with removed white
space at end of the string. `trimRight()` is an alias of this
method.
var str = " Jagathish ";
var trimmedStr = [Link]();
[Link](trimmedStr); //" Jagathish"
6.`charAt()` --> returns the character at the given index.
var str = "Jagathish";
[Link]( [Link]() ); //the default index is
[Link](1); //a
[Link](8); //h
[Link](100); //"" if max than str length return
[Link](-1); // for all negative values returns
//no type conversion takes pace so the result is em
[Link]("1"); //""
7.`charCodeAt()` --> returns the `UTF-16` character code of
Search Login
the character at the given index. All rules of `index` in
`chatAt` method is similar to `charCodeAt`.
// char code for a - 97, b =98 ,... z -122
// char code for A - 65 ... Z - 90
var str = "Jagathish";
[Link](0); // 74
[Link](1); // 97
8.`concat(arguments)` concate the arguments passed with
the source string. It doesn’t change on source string.
var str = "JavaScript";
[Link](' ', "Jeep", "."); // JavaScript Jeep.
Note: This method is not recommended , instead you can use
normal concatenation using assignment operator.
Example
var str = "JavaScript".
var name = str + " " + "Jeep" +".";
9.`includes(searchingString)` returns whether searching
String may be found in source string.
var str = "JavaScript Jeep";
[Link]("Jeep"); // true
[Link]("jeep"); // false --> case sensitive
// we can also specify the index to start search
var str = "Jeep";
[Link]("Jeep", 0); // true
[Link]("Jeep", 1); // false
10.`endsWith(searchString)` returns whether the source
Search Login
string ends with the searching string.
var str = "JavaScript Jeep";
[Link]("Jeep"); // true
[Link]("jeep"); // false
[Link]("Kepp"); // false
// we can also specify the endPosition(index+1) to
var str = "Jeep";
[Link]("J"); //false
[Link]("J", 1) // true
11.`startsWith(searchString)` returns whether the source
string starts with the searching string.
var str = "JavaScript Jeep";
[Link]("Java"); // truestr.
startsWith("java"); // falsestr.
startsWith("Ava"); // false
// we can also specify the startPosition(index) to
var str = "JAVASCRIPT"
[Link]("VA"); //false
[Link]("VA", 2) // true
[Link]("J", 1); // false --> because we are
12.`includes(searchString)` determines whether search
string found within source String
var str = "JavaScript Jeep";
[Link]("Java"); // true
[Link]("java"); // false
[Link](""); // true
[Link](); // false
we can also specify the index from which the search
str = "JavaScript";
[Link]("Java", 0); //true
Search
[Link]("Java", 1); //false Login
13 . `repeat(times)` returns a new string containing the
specified number of copies of the given [Link] value
must be non-negative and less than infinity, otherwise range
error will br thrown.
var str = "Jeep ";
var repeatedString = [Link](1); // "Jeep "
repeatedString = [Link](2); // "Jeep Jeep"
repeatedString = [Link](); // ""
repeatedString = [Link](0); // ""
14.`indexOf(searchString)` return the index of first
occurrence of search string on the source string , if the search
string not present in the source string then it returns -1.
var str = "Java Jeep JavaScript Jeep";
[Link]("Jeep"); // 5
[Link]('jeep'); // -1
// we can also specify the index from which the sea
[Link]("Java", 0); // 0
[Link]("Java", 1); // 10
15.`lastIndexOf(searchString)` return the index of last
occurrence of search string on the source string , if the search
string not present in the source string then it returns -1.
var str = "Java Jeep Java Jeep";
[Link]("Jeep"); // 15
[Link]('jeep'); // -1
16.`match(regex)` extract the result of matching a string
against a regular expression.
// Extracting
Search vowel character Login
var str = 'I love cooking.';
var regex = /[AEIOUaeiou]/gi;
var result = [Link](regex); //["I","o","e","o","
17.`search(regex)` this method test whether the source
string matches the regex provided. If the source string doesn’t
match with the regex then return -1.
var str = "str";
var regex1 = /a-z/gi;
var regex2 = /[aeiou]/gi;
[Link](regex1); // 0 ('s' matches with the rege
[Link](regex2); // -1 (because there is no matc
18.`padStart(newStringLength)` This method add the
padding (space by default) to the source string at the
beginning of the string ,so that the source string length is
converted to the provided length.
var str = "Jeep";
[Link](5); // " Jeep"
[Link](10); // " Jeep"
[Link](5, "*"); // "*Jeep"
[Link](10,"@"); // "@@@@@@Jeep"
// If the value is lower than the current string's
[Link](1); // "Jeep"
[Link](); // "Jeep"
[Link](-1); // "Jeep"
19.`padEnd(newStringLength)` This method add padding
(space by default) to the source string at the end of the string ,
so that the source string length is converted to the provided
length.
var str Search
= "Jeep";
Login
[Link](5); // "Jeep "
[Link](10); // "Jeep "
[Link](5, "*"); // "Jeep*"
[Link](10,"@"); // "Jeep@@@@@@"
// If the value is lower than the current string's
[Link](1); // "Jeep"
[Link](); // "Jeep"
[Link](-1); // "Jeep"
20.`replace(regex, stringToReplace)` this method
replaces the string with `stringToReplace` which matches
the pattern
var str = "I love dog. I love dog";
var regex = /dog/g;
[Link](regex, 'cat'); // I love cat. I love ca
21.`splice(fromIndex, toIndex)` extracts part of source
string and returns it as a new string .
var str = "JavaScript Jeep";
[Link](1); "avascript Jeep"
[Link](10); " Jeep"
[Link](11); "Jeep"
[Link](11, 12); "J"
[Link](11, 14); "Jee"
[Link](0); "Javascript Jeep"
[Link](); "Javascript Jeep"
22 . `split(separator)` this method split the string based
on the separator.
var str = "Java Jeep";
[Link](""); // ['J', 'a', 'v', 'a' ," ", 'J', 'e
[Link](" "); ["Java", "Jeep"]
Search// ["Java Jeep"]
[Link]() Login
------------------------------
// limiting number of split
var str = "this,is,a,test";
[Link](","); ["this", "is","a","test"]
[Link](",", 1); ["this"]
[Link](",", 2); ["this", "is"]
[Link](",",100); ["this", "is","a","test"]
23 . `substring(startIndex, endIndex)` returns the the
string between the start and end indexes, or to the end of the
string.
var str = "JavaScript Jeep";
[Link](11); // "Jeep"
[Link](11,12); // "J"
[Link](); // "JavaScript Jeep"
#javascript
2 4.8 GEEK
Search Login
Welcome to Morioh!
Let's write, share knowledge and earn GEEK.
Sign up