JS - Day 5

/// more methods for string - trimStart(), trimEnd(), trim()

let a = ' jaipur' // here we put space at start
let ab = a.length
console.log(ab) // prints length of string 'a' considering that space i.e. length will be 7

let abc = a.trimStart()
console.log(abc) // prints the string 'a' after trimming the space at start

let b = "jaipur " // we put space at end
let bb = b.trimEnd()
console.log(bb) // prints the string 'b' after trimming the space at end

let c = " jaipur " // we put space at both end
let cc = c.trim()
console.log(cc) // prints the string 'c' after trimming the space at both end


/// more methods - startsWith(), endsWith(), charAt()

let e = 'dharashiv'
let ea = e.startsWith('d')
console.log(ea) // prints the boolean value as true because sting 'e' starts with d

let eb = e.startsWith('dha')
console.log(eb) // prints the boolean value as true because sting 'e' starts with dha

let ec = e.startsWith('D')
console.log(ec) // prints the boolean value as false because sting 'e' don't start with capital D

let ed = e.endsWith('v')
console.log(ed) // prints the boolean value as true because sting 'e' ends with v

let ee = e.endsWith('shiv')
console.log(ee) // prints the boolean value as true because sting 'e' ends with shiv

let ef = e.charAt(0)
console.log(ef) // prints the charater at 0 index for string e // it will print d

let eg = e.charAt(5)
console.log(eg) // prints the charater at 5 index for string e // it will print s

/// more methods - slice()

//  0  1  2  3  4  5  6  7
//  k  o  l  h  a  p  u  r
// -8 -7 -6 -5 -4 -3 -2 -1

let f = "kolhapur"
let fb = f.slice(0,2)
console.log(fb) // prints characters form index 0 to 2 of 'f' string but excluding character at 2 index
// it will obly print characters at 0 & 1 index i.e. ko 

let fc = f.slice(-5,-3)
console.log(fc) // prints characters form index -5 to -3 of 'f' string but excluding character at -3 index
// it will obly print characters at -5 & -4 index i.e. ha

let fd = f.slice(-5) // we hae not put end point here // it will print all characters from -5 to rightwards
console.log(fd) // it will print hapur

let fe = f.slice(0,7) // will print all characters from 0 index to 7 excluding 7th
console.log(fe) // it will print kolhapu

Comments

Popular posts from this blog

What is IP and TCP - Marathi

JS - Day 1

JS - basic types and ways of writing function