Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript String Methods

//Here are the commonly used JavaScript String methods:

Method	Description
charAt(index)	returns the character at the specified index
concat()	joins two or more strings
replace()	replaces a string with another string
split()	converts the string to an array of strings
substr(start, length)	returns a part of a string
substring(start,end)	returns a part of a string
slice(start, end)	returns a part of a string
toLowerCase()	returns the passed string in lower case
toUpperCase()	returns the passed string in upper9 case
trim()	removes whitespace from the strings
includes()	searches for a string and returns a boolean value
search()	searches for a string and returns a position of a match
Comment

Javascript string methods

charAt()
charCodeAt()
concat()
endsWith()
includes()
indexOf()
lastIndexOf()
match()
matchAll()
repeat()
replace()
replaceAll()
search()
slice()
split()
startsWith()
substr()
substring()
toLowerCase()
toUpperCase()
toString()
trim()
valueOf()
Comment

js string methods

JS String Methods:
charAt()
Returns a character at a specified position inside a string
charCodeAt()
Gives you the unicode of character at that position
concat()
Concatenates (joins) two or more strings into one
fromCharCode()
Returns a string created from the specified sequence of UTF-16 code units
indexOf()
Provides the position of the first occurrence of a specified text within a string
lastIndexOf()
Same as indexOf() but with the last occurrence, searching backwards
match()
Retrieves the matches of a string against a search pattern
replace()
Find and replace specific text in a string
search()
Executes a search for a matching text and returns its position
slice()
Extracts a section of a string and returns it as a new string
split()
Splits a string object into an array of strings at a specified position
substr()
Similar to slice() but extracts a substring depended on a specified number of characters
substring()
Also similar to slice() but can’t accept negative indices
toLowerCase()
Convert strings to lowercase
toUpperCase()
Convert strings to uppercase
valueOf()
Returns the primitive value (that has no properties or methods) of a string object
Comment

String Methods javascript

const text1 = 'hello';
const text2 = 'world';
const text3 = '     JavaScript    ';

// concatenating two strings
const result1 = text1.concat(' ', text2);
console.log(result1); // "hello world"
// converting the text to uppercase
const result2 = text1.toUpperCase();
console.log(result2); // HELLO
// removing whitespace from the string
const result3 = text3.trim();
console.log(result3); // JavaScript
// converting the string to an array
const result4 = text1.split();
console.log(result4); // ["hello"]
// slicing the string
const result5= text1.slice(1, 3);
console.log(result5); // "el"
Comment

js string methods

// String methods:
'hello'.toUpperCase(); // "HELLO";
'LOL'.toLowerCase(); // "lol"
'    omg  '.trim(); // "omg"

// String methods with arguments:
// ==============================

//indexOf returns the index where the character is found (or -1 if not found)
'spider'.indexOf('i'); //2
'vesuvius'.indexOf('u'); //3 - only returns FIRST matching index
'cactus'.indexOf('z'); //-1 not found

// slice - returns a "slice" of a string
"pancake".slice(3); //"cake" - slice from index 3 onwards
"pancake".slice(0, 3); //"pan" - slice from index 0 up to index 3

// replace - returns a new string, with the FIRST match replaced
"pump".replace("p", "b"); //"bump" - only replaces first "p"

// String Template Literals
// Use backtick characters, NOT SINGLE QUOTES!
Comment

PREVIOUS NEXT
Code Example
Javascript :: placing card on center in angular flex layout 
Javascript :: react native jest snapshot 
Javascript :: how to add json file to mongodb 
Javascript :: puppeteer set download path 
Javascript :: polyfill for bind 
Javascript :: package.json in node js 
Javascript :: display date in javascript 
Javascript :: all   to space from string javascript 
Javascript :: sequelize findorcreate 
Javascript :: grepper extension firefox 
Javascript :: using / for division is deprecated and will be removed in dart sass 2.0.0 
Javascript :: how to make a confirm popup in vue 
Javascript :: How to print somethign to the console with javascript 
Javascript :: milliseconds to date javascript 
Javascript :: copy paste menu react native textinput disable 
Javascript :: javascript duplicate an array 
Javascript :: how to use saved image on react 
Javascript :: jquery chrome extension 
Javascript :: onload of modal jquery function 
Javascript :: js retour à la ligne 
Javascript :: get random element from string array java 
Javascript :: jquery code to make click function 
Javascript :: javascript check string lenght 
Javascript :: link reload page react 
Javascript :: javascript on uncaught exception 
Javascript :: yaml to json javascript 
Javascript :: return promise in node js 
Javascript :: js click change img 
Javascript :: get keys length jquery 
Javascript :: javascript filter array multiple conditions 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =