Javascript Strings Flashcards

1
Q

Return the first char of a specified string? Return value?

A

charAt() returns char at specified index or empty string if index not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Joins two or more strings? return value?

A
concat() returns a new string with both strings joined.
var str = 'hello'.concat(' world');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Checks whether a string ends with specified string/char? Return value?

A

endsWith() returns true is string ends with characters, and false if not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Check whether a string contains the string/characters? Return value?

A

includes() returns true if the string contains the characters, and false if not.
Second parameter can be where to start from (optional) str.includes(“world”, 12)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Returns the position of the first found occurrence of a specified value in a string

A

indexOf(searchvalue, start) returns a number representing position where the specified searchvalue occurs for the firs time or -1 if not found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Returns the position of the last found occurrence of a specified value in a search string?

A

lastIndexOf(searchvalue, start) returns a number representing the position where the specified searchvalue occurs else -1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Searches a string for a match against a regular expression?

A

.match(/ain/g) return array containing the matches, one item for each match or null if no match found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced?

A

.replace(“This”, “That”)

First searchvalue is pattern, second parameter is replacement pattern. Can also take regex .replace(/blue/g, “red”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Extracts a part of a string and returns a new string?

A

.slice(1,5) First parameter is required and the position where to begin the extraction. Second parameter is end and optional and the position (up to but not including).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Checks whether a string begins with a specified characters?

A

.startsWith(“Hello”) method returns true if the string begins with characters else false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Extracts the characters from a string, beginning at a specified start position, and through the specified number of characters?

A

.substr(1,4) First parameter is the position where to start extraction, second parameter is optional and the number of characters to extract. A new string is returned.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Converts a string to uppercase letters

A

.toUppderCase()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Converts a string to lowercase?

A

.toLowerCase()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Removes whitespace from both ends of a string?

A

.trim

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Returns the primitive value of a String object?

A

.valueOf()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly