Mozilla "strings" Flashcards
The String object’s _________method returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.
charAt()
The ______ method concatenates the string arguments to the calling string and returns a new string.
concat()
The _______ method determines whether a string ends with the characters of a specified string, returning true or false as appropriate.
endsWith()
the endsWith() returns __________
a boolean
const str1 = ‘Cats are the best!’;
console.log(str1.endsWith('best', 17)); // expected output:
const str2 = ‘Is this a question’;
console.log(str2.endsWith('?')); // expected output:
true
false
const str1 = 'Cats are the best!'; console.log(str1.endsWith('best!', 17)); // expected output:
false
The __________method determines whether one string may be found within another string, returning true or false as appropriate.
includes()
includes() returns a _____________
boolean
The _____________method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
indexOf()
var paragraph = ‘The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?’;
var searchTerm = 'dog'; var indexOfFirst = paragraph.indexOf(searchTerm);
console.log(indexOfFirst); // expected output: \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_
40
The _____________ method returns the index within the calling String object of the last occurrence of the specified value, searching backwards from fromIndex. Returns -1 if the value is not found.
lastIndexOf()
The ______________ method returns the calling string value converted to uppercase (the value will be converted to a________ if it isn’t one).
toUpperCase()
string
The ____________ method returns the calling string value converted to lower case.
toLowerCase()
The ____________ method removes whitespace from both ends of a string. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).
trim()
var greeting = ' Hello world! '; console.log(greeting.trim());
“Hello world!”
The _____________ method removes whitespace from the end of a string. trimRight() is an alias of this method.
trimEnd()
var greeting = ‘ Hello world! ‘;
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: " Hello world!";
greeting.trimEnd()
The _____________ method removes whitespace from the beginning of a string. trimLeft() is an alias of this method
trimStart()
var greeting = ' Hello world! '; console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: "Hello world! ";
greeting.trimStart()
The ____________ method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
split()
var str = ‘The quick brown fox jumps over the lazy dog.’;
var words = str.split(' '); console.log(words[3]); // expected output:
“fox”
var str = ‘The quick brown fox jumps over the lazy dog.’;
var words = str.split(' '); console.log(\_\_\_\_\_\_\_\_\_\_); // expected output: "fox"
words[3]
var str = ‘The quick brown fox jumps over the lazy dog.’;
var chars = str.split(''); console.log(chars[8]); // expected output:
“k”
var str = ‘The quick brown fox jumps over the lazy dog.’;
var chars = str.split(''); console.log(\_\_\_\_\_\_\_\_\_\_); // expected output: "k"
chars[8]
The split() method splits a String object into an __________ of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
array
split()
method splits a String object into an array of strings by separating the string into substrings, using a specified separator string to determine where to make each split.
includes()
determines whether one string may be found within another string, returning true or false as appropriate.
The ___________method returns the part of the string between the start and end indexes, or to the end of the string.
substring()
var str = ‘Mozilla’;
console.log(str.substring(1, 3)); // expected output:
console.log(str.substring(2)); // expected output:
“oz”
“zilla”
str.substring(_________[,_________])
indexStart
indexEnd
const str1 = 'Cats are the best!'; console.log(str1.endsWith('best!'));
true
The __________method pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length. The padding is applied from the end (right) of the current string.
padEnd()
const str1 = ‘Breaded Mushrooms’;
console.log(str1.padEnd(25, '.')); // expected output:
const str2 = ‘200’;
console.log(str2.padEnd(5)); // expected output:
“Breaded Mushrooms……..”
“200 “
The ______ method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start (left) of the current string.
padStart()
const str1 = ‘5’;
console.log(str1.padStart(2, 0)); // expected output:
“05”
const fullNumber = '2034399002125581'; const last4Digits = fullNumber.slice(-4); const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
console.log(maskedNumber); // expected output:
“****5581”
const str1 = ‘5’;
console.log(str1.padStart(2)); // expected output:
” 5”
The _______ method extracts a section of a string and returns it as a new string, without modifying the original string.
slice()
var str = ‘The quick brown fox jumps over the lazy dog.’;
console.log(str.slice(31)); // expected output:
“the lazy dog.”
var str = ‘The quick brown fox jumps over the lazy dog.’;
console.log(str.slice(4, 19)); // expected output:
“quick brown fox”
var str = ‘The quick brown fox jumps over the lazy dog.’;
;console.log(str.slice(-4)); // expected output:
“dog.
var str = ‘The quick brown fox jumps over the lazy dog.’;
console.log(str.slice(-9, -5)); // expected output:
“lazy”
The ___________ method determines whether a string begins with the characters of a specified string, returning true or false as appropriate.
startsWith()
const str1 = 'Saturday night plans'; console.log(str1.startsWith('Sat', 3)); // expected output:
false
const fullNumber = '2034399002125581'; const last4Digits = fullNumber.slice(-4)
console.log(last4Digits);
5581
‘abc’.padStart(1); //
“abc”
‘abc’.padStart(10, “foo”); //
“foofoofabc”
‘abc’.padStart(6,”123465”); //
“123abc”
‘abc’.padStart(8, “0”); //
“00000abc”