let string1 = “wow”;
string1.charAt(1)
// o
.charCodeAt() // get the character code at specified index
.concat() // joins two strings together
.endsWith() // checks if a string ends with something
String.fromCharCode(114) // 'r'
.includes() // checks if a string includes something
.indexOf() // gets the first index of something in a string
.lastIndexOf() // gets the last index of a value in a string
.match() // use a regular expression
const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const regex = /[A-Z]/g;
const found = paragraph.match(regex);
console.log(found);
// Expected output: Array ["T", "I"]
.repeat() // returns the string a certain number of times, over and over
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
console.log(p.replace('dog', 'monkey'));
// Expected output: "The quick brown fox jumps over the lazy monkey. If the dog reacted, was it really lazy?"
const regex = /Dog/i;
console.log(p.replace(regex, 'ferret'));
// Expected output: "The quick brown fox jumps over the lazy ferret. If the dog reacted, was it really lazy?"
.search() // search using regex to find the position
.slice(a, b) // gets characters from string
// starting from index a, and up to b (exclusive)
.split(" ") // splits the string on spaces
.startsWith() // checks if the string starts with a value
.substr(a, b) // starts at a, and goes for b number of characters .. kinda deprecated
.toLowerCase()
.toUpperCase()
.trim() // trim whitespace on either side of the string
.trimStart() // trims whitespace at the beginning
.trimEnd() // trims whitepsace at the end
padStart(targetLength, padString)
const fullNumber = '2034399002125581';
const last4Digits = fullNumber.slice(-4);
const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
console.log(maskedNumber);
// Expected output: "************5581"
// you can also padEnd()