JS Strings Flashcards Preview

Javascript is a Language > JS Strings > Flashcards

Flashcards in JS Strings Deck (23):
1

.charAt(index)

str.charAt(0);

returns character at specified index

2

.charCodeAt(index)

str.charCodeAt(0);

returns unicode of character at specified index

3

.concat(str, ?...)

str1.concat(str2, str3, ...);

joins 2+ strings and returns one string

4

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

str.endsWith("bye.");

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

5

String.fromCharCode(char_code,...)

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

converts a unicode number to a character

6

.includes(searchvalue, ?startindex)

str.includes("world");

returns boolean whether string includes specified string

7

.indexOf(searchvalue, ?start)

str.indexOf("world");

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

8

.lastIndexOf(searchvalue, ?start)

str.lastIndexOf("world");

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

9

.localCompare(comparestring)

str1.localCompare(str2);

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

10

.match(regex)

str.match(/rain/i);

returns an array of values matching the regex

11

.repeat(number)

str.repeat(2)

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

12

.replace(searchvalue,newvalue)

str.replace(/blue/g, "red");

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

13

.search(searchvalue)

str.search("world");

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

14

string.slice(start, ?end)

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

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

15

string.split(separator, ?limit)

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

returns an Array, containing the splitted values

16

string.startsWith(searchvalue, ?start)

str.startsWith("Hello");

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

17

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

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

18

string.substring(start, ?end)

if start negative then defaults to zero

returns a new String containing the extracted characters

19

string.toLowerCase()

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

20

string.toString()

returns a String, representing the value of a string

21

string.toUpperCase()

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

22

string.trim()

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

23

string.valueOf()
(not usually called)

returns a String, representing the primitive value of a string