Strings Flashcards

1
Q

length()

A

Returns the length of the string
* PROPERTY, NOT A METHOD
* Counts code units, not characters
*

The length of the string

String.length()

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

charAt()

A

New string of single UTF-16 code unit @ pecified offset into the string
* charAt(index)
* if index is out of range, returns empty string

String representing the character @ index

String.prototype.charAt()

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

concat()

A

Concatenates N number of strings
* concat(strN)
* Converts elements into string values
* concat() coerces its arguments directly to strings (while + coerces to primitives first)
*

New string containing the combined text of the strings provided

String.prototype.concat()

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

indexOf()

A

Returns the index of the first occurrence of a specified substring in the string, or -1 if not present
* indexOf(searchString, position)
* searchString is the substring that is searched within the called string
* Case sensitive!

Index of the first occurrence of searchString

String.prototype.indexOf()

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

lastIndexOf()

A

Returns the index of the last occurrence of a specified substring in the string, or -1 if not found.
* lastIndexOf(searchString, position)
* Case sensitive!

The index of the last occurrence of searchString found, if not, -1

Array.prototype.lastIndexOf()

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

replace()

A

Replaces a specified substring with another string
* String pattern will only be replaced once

New string w/ N matches of the pattern replaced by specified replacement

String.prototype.replace(pattern, replacement)

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

slice()

A

Returns a portion of the string
* Extracts up to, but not including indexEnd
*

A new string containing the extracted section of the string

String.prototype.slice(indexStart, indexEnd)

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

split()

A

Splits the string into an array of substrings based on specified separator
* if separator is undefined, target string is returned wrapped in an array

An Array of strings, split @ each point separator occurs in the string

String.prototype.split(separator, limit )

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

substring()

A

Returns a substring between two specified indexes
* extracts characters from indexStart up to not including indexEnd

A new string containing the specified part of the given string

String.prototype.substring(indexStart, indexEnd)

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

toLowerCase()

A

Converts the string to lowercase
* Non-mutating method
* Does not affect the value of str itself

A new string representing the calling string converted to lower case

String.prototype.toLowerCase()

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

toUpperCase()

A

Converts the string to uppercase
* Non-mutating method
* Does not affect the value of str itself

A new string representing the calling string converted to upper case

String.prototype.toUpperCase()

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

trim()

A

Removes whitespace from the beginning and end of the string
* if there is no whitespace, essentially coppies str
* For more options, use trimStart() or trimEnd()

New string stripped of whitespace from both beginning and end

String.prototype.trim()

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