String Methods Flashcards
(10 cards)
What are the 2 operators used to build and concatenate strings?
What is a string method you could also use to achieve this?
+
+=
const str1 = 'Hello'; const str2 = 'World'; str1.concat(' ', str2);
What are the 2 ways to access a single character in a string?
- charAt() = string.charAt(i)
- bracket notation = string[i]
*When using bracket notation for character access, attempting to delete or assign a value to these properties will not succeed
let s= "1+2" what does eval(s) return?
3
What symbol is used for escape notation within a string literal?
\
What can you include inside of string “” to indicate that the string value will continue on the next line?
\ let str= "This is \a very long string";
.includes()
- What is it’s purpose?
- What is the syntax?
- What does it return?
- determines whether one string can be found within another string
- myString.includes(“word”)
- true/false
.endsWith()
- What is it’s purpose?
- What is the syntax?
- What does it return?
- determines whether a string ends with the characters of a specified string
- myString.endsWith(“hello”)
- true/false
What method(s) could you use to determine if a string can be found within another string?
.includes()
myString.includes(“another string”)
returns true/false
indexOf()
myString.indexOf(searchTerm)
returns -1 if term does not exist in the string
What method could you use to determine if a string ends with the characters of a specified string?
.endsWith()
myString.endsWith(“another string”)
returns true/false
.indexOf()
- What is it’s purpose?
- What is the syntax?
- What does it return?
- returns the index of first occurring index of a specified value within a string
2. const paragraph = 'The quick brown fox jumps'; const searchTerm = 'fox'; const indexOfFirst = paragraph.indexOf(searchTerm);
- the index of the specified value
* returns -1 if search term does not exist