Introduction to JavaScript String Methods

localeCompare Method
let x ='a'
let y ='b'
console.log(x.localeCompare(y));
  //here a is not coming after b so -1 
  //checks whether the compare string comes after or before the given string 
  //all uppercase letters come before lower case letters in js 
Output
-1
charAt Method
let x = 'satish'
console.log(x.charAt(0));
Output
s
concat method
let x = 'Satish'
console.log(x.concat('C J')); 
Output
SatishC J
includes method
let x = 'Satish teaches javaScript'
console.log(x.includes("teach"));
Output
true
endswith method
let x = 'Satish teaches javaScript'
console.log(x.endsWith('ish',6));//checks if the first 6 characters ends with ish
Output
true
startswith method
 let x = 'Satish teaches javaScript'
console.log(x.startsWith('teach',7));
//checks if the string starts with teach in index 7 
Output
true
indexOf method
 let x = 'Satish teaches javaScript'
console.log(x.indexOf("teaches")); //returns the index where match occurs
//-1 is returned for no match
Output
7
lastindexof method
let x = 'Satish teaches javaScript'
  console.log(x.lastIndexOf("Satish"));
Output
0
length method
let x = 'Satish'
console.log(x.length);
Output
6
repeat method
let x = 'Satish'
console.log(x.repeat(3));
Output
SatishSatishSatish
replace method
let x = 'Mr. Satish'
console.log(x.replace('Mr','Dr'));
Output
Dr. Satish
slice method
let x = 'Satish'
  console.log(x.slice(0,3));
Output
Sat
replace method in Arrays
let x = 'Mr. Satish'
console.log(x.replace('Mr','Dr'));
Output
Dr. Satish
split method
let x = 'Satish is teaching javascript'
const k = x.split(" ");
for(let i of k)
{
  console.log(i);
}
Output
Satish is teaching javascript
substring method
let x ="Satish"
console.log(x.substring(0,2));
Output
Sa
toLowerCase method
let x ="Satish"
console.log(x.toLowerCase());
Output
satish
touppercase method
let x ="Satish"
console.log(x.toUpperCase());
Output
SATISH
trim method
let x =" Satish "
console.log(x.trim());
//variations are trimStart() and trimEnd()
Output
Satish