let str = 'hello'
typeof str
let strObj = new String ('hello')
typeof strObj
strObj instanceof Object
strObj instanceof String
str.valueOf()
str.toString()
str.length
str.concat(' world')
console.log (str.slice(0,3))
console.log (str.substring())
console.log (str.substr(2,2))
console.log(str.indexOf('o',2))
console.log(str.lastIndexOf('o',4))
str.startsWith('llo')
str.endsWith('llo')
str.includes('llo')
str.trim()
str.trimLeft()
str.trimRight()
str.repeat(1)
str.padStart(8,'xx')
str.padEnd(8,'xx')
str.toLocaleLowerCase()
str.toLocaleUpperCase()
str.toLowerCase()
str.toUpperCase()
console.log(str.match(/o/g))
str.search(/o/)
str.replace('h','H')
console.log( str.replace('l','x'))
console.log(str.replace(/l/g,'x') )
let arr = [
{color:'red',sort:1},
{color:'yellow',sort:8},
{color:'blue',sort:2},
{color:'red',sort:9},
{color:'yellow',sort:9},
{color:'red',sort:9},
]
arr.sort((a,b)=>{
if(a.sort===b.sort){
if(a.color>b.color){
return 1
}else if(a.color===b.color){
return 0
}else{
return -1
}
}else if (a.sort > b.sort) {
return 0
}else{
return -1
}
})
console.log(arr)