TIL startWith
POSTED ON:
TAGS: mdn javascript string
Getting a boolean result of true or false, depending on if the string startsWith a specific substring.
How it works: #
//startswith
let str = 'To be, or not to be, that is the question.'
console.log(str.startsWith('To be')) // true
console.log(str.startsWith('not to be')) // false
console.log(str.startsWith('not to be', 10)) // true
I was looking at ripping string apart by spaces (using the String.prototype.split method), then found this other neat method to do string comparison.
Related TILs
Tagged: mdn