JS: String property & methods
//* String property & methods *//
//A) String property
1) length : returns the length of string
//B) String methods
1) slice()
2) replace()
3) toUpperCase()
4) toLowerCase()
5) concat() : joins two different strings
6) trim() : removes whitespace from both sides of a string
7) trimStart() : removes whitespace only from the start of a string
8) trimEnd() : removes whitespace only from the end of a string
9) charAt() : method returns the character at a specified index (position) in a string
10) startsWith() : Checks whether a string begins with specified characters
11) endsWith() : Checks whether a string ends with specified characters
12) includes() : Returns if a string contains a specified value
13) indexOf() : Returns the index (position) of the first occurrence of a value in a string
14) repeat() : returns a new string with a number of copies of a string
//* String property & methods: Lecture 1 *//
//A) String property
1) length : returns the length of string
//----------------------
//B) String methods
1) charAt() : method returns the character at a specified index (position) in a string
2) startsWith() : Checks whether a string begins with specified characters
3) endsWith() : Checks whether a string ends with specified characters
4) includes() : Returns if a string contains a specified value
5) indexOf() : Returns the index (position) of the first occurrence of a value in a string
6) repeat() : returns a new string with a number of copies of a string
7) concat() : joins two different strings
//* String property & methods: Lecture 1 *//
//A) String property
//1) length : returns the length of string
let h1 = 'Shriram'
console.log(h1.length)
let h2 = 'sachin ramesh tendulkar'
console.log(h2.length)
//----------------------
//B) String methods
// 1) charAt() : method returns the character at a specified index (position) in a string
let h3 = "Suhas"
console.log(h3.charAt(0))
console.log(h3.charAt(2))
// 2) startsWith() : Checks whether a string begins with specified characters and returns boolean value
let h4 = "tuljapur"
console.log(h4.startsWith('t'))
console.log(h4.startsWith('u'))
console.log(h4.startsWith('tul'))
// 3) endsWith() : Checks whether a string ends with specified characters and returns boolean value
let h5 = 'dharashiv'
console.log(h5.endsWith('v'))
console.log(h5.endsWith('i'))
console.log(h5.endsWith('shiv'))
// 4) includes() : Returns boolean value if a string contains a specified value
let h6 = 'Mumbai'
console.log(h6.includes('M'))
console.log(h6.includes('u'))
console.log(h6.includes('j'))
// 5) indexOf() : Returns the index (position) of the first occurrence of a value in a string
let h7 = "Kolhapur"
console.log(h7.indexOf('K'))
console.log(h7.indexOf('a'))
let h8 = 'Pralhad'
console.log(h8.indexOf('a'))
// 6) repeat() : returns a new string with a number of copies of a string
let h9 = 'Ramesh'
console.log(h9.repeat(2))
// 7) concat() : joins two different strings
let h10 = "Rahul"
let h11 = " Dravid "
console.log(h10.concat(h11))
console.log(h11.concat(h10))
//---------------------------------------------
//* String property & methods: Lecture 2 *//
//B) String methods:
// 8) slice(): extracts a part of a string and returns the extracted part in a new string.
// 01234567
let h12 = 'Sinhagad'
console.log(h12.slice(0,5))
let h13 = 'mango, banana'
console.log(h13.slice(8,12))
// 9) replace(): method replaces a specified value with another value in a string
let h14 = 'Ramesh'
console.log(h14.replace('Ra','U'))
let m1 = 'Tuljai'
console.log(m1.replace('T','A'))
let h15 = 'Virendra Sehwag'
console.log(h15.replace('Virendra','Ram'))
// 10) toUpperCase(): A string is converted to upper case
let h16 = 'yuvraj singh'
console.log(h16.toUpperCase())
let h17 = 'virat kohli'
console.log(h17.toUpperCase())
// 11) toLowerCase(): A string is converted to upper lowercase
let h18 = 'ROHIT SHARMA'
console.log(h18.toLocaleLowerCase())
let h19 = 'UMESH YADAV'
console.log(h19.toLowerCase())
// 12) trim(): removes whitespace from both sides of a string
let h20 = ' Hello '
console.log(h20.trim())
let h21 = ' Welcome '
console.log(h21.trim())
// 13) trimStart(): removes whitespace only from the start of a string
let h22 = ' Hanuman'
console.log(h22.trimStart())
let h23 = ' Sita'
console.log(h23.trimStart())
// 14) trimEnd(): removes whitespace only from the end of a string
let h24 = 'Laxman '
console.log(h24.trimEnd())
let h25 = 'Ram '
console.log(h25.trimEnd())
Comments
Post a Comment