Today I Learned - Rocky Kev

TIL startWith

POSTED ON:

TAGS:

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.

mdn - startsWith


Related TILs

Tagged:

TIL fancy methods to transform Javascript Objects

You can use Object.entries(), Object.keys(), Object.fromEntries()...

TIL How to steal localData using an XSS attack

But that's just a red flag that opens the door to bigger issues.

TIL Clear-Site-Data

The Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website. It allows web developers to have more control over the data stored by a client browser for their origins.