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
1.length
Learn How to Create
A WordPress
var str = "Jagathish"; Maintenance Mode
str.length; //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 = str.toUpperCase(); Build & Deploy A
YouTube Thumbnail
console.log(str);//Jagathish
Fetcher App with
console.log(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 = str.toLowerCase(); JavaScript
console.log(str);//Jagathish
8 months ago
console.log(str2);//jagathish
How to Build a
Chatbot Application
3.`trim()` --> returns a new string with removed white space with Node.js
from start and end of the string. 9 months ago
var str Search
= " Jagathish ";var trimmedStr = str.tri
Login
var trimmedStr1 = str1.trim();
console.log(trimmedStr1); //"J aga"var str2 = "J
var trimmedStr2 = str2.trim();
console.log(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 = str.trimStart();
console.log(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 = str.trimEnd();
console.log(trimmedStr); //" Jagathish"
6.`charAt()` --> returns the character at the given index.
var str = "Jagathish";
console.log( str.charAt() ); //the default index is
str.charAt(1); //a
str.charAt(8); //h
str.charAt(100); //"" if max than str length return
str.charAt(-1); // for all negative values returns
//no type conversion takes pace so the result is em
str.charAt("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";
str.charCodeAt(0); // 74
str.charCodeAt(1); // 97
8.`concat(arguments)` concate the arguments passed with
the source string. It doesn’t change on source string.
var str = "JavaScript";
str.concat(' ', "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";
str.includes("Jeep"); // true
str.includes("jeep"); // false --> case sensitive
// we can also specify the index to start search
var str = "Jeep";
str.includes("Jeep", 0); // true
str.includes("Jeep", 1); // false
10.`endsWith(searchString)` returns whether the source
Search Login
string ends with the searching string.
var str = "JavaScript Jeep";
str.endsWith("Jeep"); // true
str.endsWith("jeep"); // false
str.endsWith("Kepp"); // false
// we can also specify the endPosition(index+1) to
var str = "Jeep";
str.endsWith("J"); //false
str.endsWith("J", 1) // true
11.`startsWith(searchString)` returns whether the source
string starts with the searching string.
var str = "JavaScript Jeep";
str.startsWith("Java"); // truestr.
startsWith("java"); // falsestr.
startsWith("Ava"); // false
// we can also specify the startPosition(index) to
var str = "JAVASCRIPT"
str.startsWith("VA"); //false
str.startsWith("VA", 2) // true
str.startsWith("J", 1); // false --> because we are
12.`includes(searchString)` determines whether search
string found within source String
var str = "JavaScript Jeep";
str.includes("Java"); // true
str.includes("java"); // false
str.includes(""); // true
str.includes(); // false
we can also specify the index from which the search
str = "JavaScript";
str.include("Java", 0); //true
Search
str.include("Java", 1); //false Login
13 . `repeat(times)` returns a new string containing the
specified number of copies of the given string.Repeat value
must be non-negative and less than infinity, otherwise range
error will br thrown.
var str = "Jeep ";
var repeatedString = str.repeat(1); // "Jeep "
repeatedString = str.repeat(2); // "Jeep Jeep"
repeatedString = str.repeat(); // ""
repeatedString = str.repeat(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";
str.indexOf("Jeep"); // 5
str.indexOf('jeep'); // -1
// we can also specify the index from which the sea
str.indexOf("Java", 0); // 0
str.indexOf("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";
str.lastIndexOf("Jeep"); // 15
str.lastIndexOf('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 = str.match(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;
str.search(regex1); // 0 ('s' matches with the rege
str.search(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";
str.padStart(5); // " Jeep"
str.padStart(10); // " Jeep"
str.padStart(5, "*"); // "*Jeep"
str.padStart(10,"@"); // "@@@@@@Jeep"
// If the value is lower than the current string's
str.padStart(1); // "Jeep"
str.padStart(); // "Jeep"
str.padStart(-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
str.padEnd(5); // "Jeep "
str.padEnd(10); // "Jeep "
str.padEnd(5, "*"); // "Jeep*"
str.padEnd(10,"@"); // "Jeep@@@@@@"
// If the value is lower than the current string's
str.padEnd(1); // "Jeep"
str.padEnd(); // "Jeep"
str.padEnd(-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;
str.replace(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";
str.slice(1); "avascript Jeep"
str.slice(10); " Jeep"
str.slice(11); "Jeep"
str.slice(11, 12); "J"
str.slice(11, 14); "Jee"
str.slice(0); "Javascript Jeep"
str.slice(); "Javascript Jeep"
22 . `split(separator)` this method split the string based
on the separator.
var str = "Java Jeep";
str.split(""); // ['J', 'a', 'v', 'a' ," ", 'J', 'e
str.split(" "); ["Java", "Jeep"]
Search// ["Java Jeep"]
str.split() Login
------------------------------
// limiting number of split
var str = "this,is,a,test";
str.split(","); ["this", "is","a","test"]
str.split(",", 1); ["this"]
str.split(",", 2); ["this", "is"]
str.split(",",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";
str.substring(11); // "Jeep"
str.substring(11,12); // "J"
str.substring(); // "JavaScript Jeep"
#javascript
2 4.8 GEEK
Search Login
Welcome to Morioh!
Let's write, share knowledge and earn GEEK.
Sign up