Strings Flashcards

1
Q

string object

A

let str = new String();

Object constructor, creates a new String OBJECT. You can still execute string methods on it, but it is considered an object.

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

string literal

A

let str = “string”;

The primitive version of a string. When calling methods on this variable, it is autoboxed into a string object.

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

charAt(index)

A

returns the character at the specified index

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

charCodeAt(index)

A

returns the Unicode of the character at the specified index

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

concat(string1, string2, …)

A

concats the passed in strings to the calling string. returns the newly concatted string

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

endsWith(string OR char)

A

checks if the calling string ends with the input string or character. returns a boolean

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

fromCharCode(unicode)

A

converts the unicode value into a character. returns that character

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

includes(string OR char)

A

checks whether a string contains the specified string/characters. returns a boolean

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

indexOf(any primitive)

A

returns the first index of the specified value in the calling string

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

lastIndexOf(any primitive)

A

returns the position of the last found occurrence of the specified value in the calling string

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

localeCompare(string)

A

compares two strings in the current locale. returns either 0, -1, or 1 (though you should simply check for values > or < zero, not specifically -1 & 1)

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

repeat(number, string)

A

returns a new string containing the passed in string repeated the passed in number of times

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

replace(any primitive OR regex, string)

A

returns a new string with the first occurrence of the primitive value or regex replaced with the passed in string

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

replaceAll(any primitive OR regex, string)

A

returns a new string with all of the occurrences of the primitive value or regex replaced with the passed in string

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

search(any primitive OR regex)

A

returns the index of the specified primitive or regex. Use this if you are using regex, otherwise indexOf will be the faster version

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

slice(index one, index two)

A

returns a new string made up of the extracted portion of a string. uses index one and index two to determine the length & location of the substring. If only a single index is provided, it returns from that index to the end of the string.

NOTE: also works on arrays, also accepts negative values!!!!!

17
Q

split(splitting character/string)

A

returns an array of substrings made up of the original string divided by the splitting character

ex. “hello there”.split(‘ ‘) => [“hello”, “there”]

18
Q

startsWith(string OR character)

A

checks whether or not the string begins with the specified string or character

19
Q

substr(index start, length)

A

this returns a new string, which is a substring of the original calling string. the substring starts at the given starting index and extends to the length specified in the second arg.

20
Q

substring(index one, index two)

A

returns a new string made up of the extracted portion of a string. uses index one and index two to determine the length & location of the substring. If only a single index is provided, it returns from that index to the end of the string.

just use slice

21
Q

toLowerCase()

A

Converts a string to lowercase letters

22
Q

toUpperCase()

A

Converts a string to uppercase letters

23
Q

trim()

A

removes additional whitespace from the ends of the calling string and returns a new modified/updated string

24
Q

valueOf()

A

returns the primitive value of the string object (calling string)

25
Q

padStart(length, pad value)

padEnd(length, pad value)

A

returns a string that is padded to length using the pad value as the padding