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()