String Methods Flashcards

1
Q

Property that returns the length of a string

A

String.length

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

Returns the index of the first occurrence of a specified string in a string

A

indexOf()

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

Returns the index of the last occurrence of a specified text in a string by searching backwards

A

lastIndexOf()

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

indexOf() and lastIndexOf() return what if the text is not found?

A

-1

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

How to add a starting position for indexOf()/lastIndexOf()

A

indexOf(string, 15)

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

Searches for a string with a specified value and returns the position to the match

A

search()

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

What is the difference between search() and indexOf()?

A

search() cannot take a second start position argument.

indexOf() cannot take powerful search values/regular expressions

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

Extracts the part of a string and returns the extracted part in a new string with the second parameter specifying the end index.

A

slice(start, end*)

*end can be ommited to slice out the rest of the string. a negative start can be used to count from the end.

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

Extract the part of a string and returns the extracted part in a new string but cannot take a negative index.

A

substring(start, end)

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

Extract the part of a string and returns the extracted part in a new strung with the second parameter specifying length

A

substr(start, length)

a negative start can be used to count from the end.

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

Replaces the specified value with another value in a string

A

replace()
*To replace case insensitive, use a regular expression with an /i flag (insensitive)
*
To replace all matches, use a regular expression with a /g flag (global match):

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

Convert a string to uppercase

A

toUpperCase()

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

Convert a string to lowercase

A

toLowerCase()

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

Joins two or more strings. works like a plus operator

A

concat()

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

Remove white space from both sides of a string

A

trim()

*not supported by internet Explorer 8. Use replace() with a regular expression instead.

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

Returns the character at a specified index in a string

A

CharAt()

17
Q

Returns the unicode of the character at a specified index in a string (in UTF-16 code, an int between 0 and 65535)

A

CharCodeAt()

18
Q

How does property access work in a string?

A
  • It makes strings look like arrays (but they are not)
  • If no character is found, [ ] returns undefined
  • It is read only. str[0] = “A” gives no error (but does not work!)
19
Q

Convert a string to an array

A

split(seperator*)

*takes in a string as separator. if omitted, returns an array with the whole string in index[0]