JS Strings Flashcards

1
Q

.charAt(index)

str.charAt(0);

A

returns character at specified index

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

.charCodeAt(index)

str.charCodeAt(0);

A

returns unicode of character at specified index

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

.concat(str, ?…)

str1.concat(str2, str3, …);

A

joins 2+ strings and returns one string

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

.endsWith(searchvalue, ?length)
default length is string length

str.endsWith(“bye.”);

A

returns boolean, checks whether string ends with specified characters (case-sensitive)

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

String.fromCharCode(char_code,…)

String.fromCharCode(72, 69, 76, 76, 79);

A

converts a unicode number to a character

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

.includes(searchvalue, ?startindex)

str.includes(“world”);

A

returns boolean whether string includes specified string

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

.indexOf(searchvalue, ?start)

str.indexOf(“world”);

A

returns index of first occurrence of search value in string, returns -1 if no value found

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

.lastIndexOf(searchvalue, ?start)

str.lastIndexOf(“world”);

A

returns index of last occurrence of search value in string, returns -1 if no value found

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

.localCompare(comparestring)

str1.localCompare(str2);

A

compares two string in the current locale, returns -1,0,1 depending on sort order comparing; -1 reference sorts before compare string…

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

.match(regex)

str.match(/rain/i);

A

returns an array of values matching the regex

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

.repeat(number)

str.repeat(2)

A

returns a new string with set number of duplicates of reference string

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

.replace(searchvalue,newvalue)

str.replace(/blue/g, “red”);

A

returns new string replacing search value (string or regex) with new value

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

.search(searchvalue)

str.search(“world”);

A

returns a Number, representing the position of the first occurrence of the specified searchvalue, or -1 if no match is found

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

string.slice(start, ?end)

str. slice(1, 5); (incl 1, excl 5)
str. slice(0) extracts whole string
str. slice(-1) extracts last character

A

returns a String, representing the extracted part of the string.

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

string.split(separator, ?limit)

str.split(“ “);
str.split(“”) splits every value
limit cuts off array after set number of items

A

returns an Array, containing the splitted values

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

string. startsWith(searchvalue, ?start)

str. startsWith(“Hello”);

A

Returns true if the string starts with the value, otherwise it returns false

17
Q

string.substr(start, ?length)

str.substr(2);
returns remainder of string if no length
If length is 0 or negative, an empty string is returned.
if start negative then from end of string

A

Returns a new String, containing the extracted part of the text.

18
Q

string.substring(start, ?end)

if start negative then defaults to zero

A

returns a new String containing the extracted characters

19
Q

string.toLowerCase()

A

returns a String, representing the value of a string converted to lowercase

20
Q

string.toString()

A

returns a String, representing the value of a string

21
Q

string.toUpperCase()

A

returns a String, representing the value of a string converted to uppercase

22
Q

string.trim()

A

returns a String, representing the string with removed whitespace from both ends

23
Q

string.valueOf()

not usually called

A

returns a String, representing the primitive value of a string