What method allows you to see if a string begins with a certain string?
var string = 'RFB2';
string.startsWith('RFB')
> true!Would startWidth allow for case sensitivity?
No
What does the second param of startsWith allow you to do?
Starts after X characters
const string = 'RFB2';
string.startsWith('RFB', 3)
> true!What method allows you to see if a string ends with a certain string?
const string = '2-AC-2018-JZ';
string.endsWith('JZ')
> true!How would you selectively use endsWith to ignore the last few characters of a string
Use the second parameter to choose how many characters from the start of the string you want to check:
const string = ‘ADGDRT001’;
string.endsWidth(‘RT’,6);
What method would you use to check for the presence of ‘ac’ in a string?
.includes(‘ac’);
What method allows you to repeat a string?
.repeat(‘string’);
What would .repeat() be useful. Give an example.
to format text in a left pad function.
function leftPad(str, length = 20) {
return `- ${ ' '.repeat(length - str.length) }`;
}