String-Methods Flashcards

1
Q

fromCharChode

A
String.fromCharChode(num code1, ...)
=>  {str} string created by sequence of char-codes
#safe
#static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

charCodeAt

A
.charCodeAt(num index)
=>  {num} numeric Unicode value at `index` of string
#safe

index
- range: 0 - length-1, else NaN returned

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

indexOf

A
.indexOf(str search, num start=0)
=>  {num} index of `search` match, else -1
#safe

start

  • if < 0, search = 0
  • if >= length, returns -1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

lastIndexOf

A
.lastIndexOf(str search, num start=length)
=>  {num} index of `search` match, searched from right-to-left, else -1
#safe

start

  • if < 0, search = 0
  • if > length, returns -1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

match

A
.match(reg search)
=>  {array|null} array of `search` match results, or null if none were found
#safe

search

  • if given a non-regexp, will convert into one via new RegExp(search).
  • if search has the g flag, the array will be matches only: [match1, match2, …]
  • if the g flag is absent, the returned array will be: [match, captureParens, ..., index: match-index, input: provided-string]
  • (this is identical to regexp.exec(string))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

replace

A
.replace(str|reg search, str|func replace)
=>  {str} string with `search` replaced by `replace`
#safe

search

  • if string or regexp w/o g flag, replaces at most 1 time;
  • if regexp w/ g flag replaces all times.
replace
- if string, can use characters
  \$\$ => $
  $& => matched substring
  $` => text prior to match
  $' => text after match
  $n => capturing-parens of `search` regexp pattern
- if function, will be called for every match and the returned value used as the search-replacement; arguments are identical to the pattern.exec() or str.match() array (when pattern omits g-flag):
  - match  - matched substring
  - p1...  - capturing parens 1, etc. (if applies)
  - index  - index when match starts
  - input  - input-string
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

search

A
.search(reg search)
=>  {num} index of `search` match, else -1
#safe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

slice

A
.slice(num start, num end=length)
=>  {str} sub-string of string from start to end index
#safe

start

  • if < 0, start=length+start
  • if > length, returns ‘’

end

  • exclusive
  • if < 0, end=length+end
  • if > length, returns ‘’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

split

A
.split(str|reg separator, num limit=none)
=>  {arr} array of substrings split by `separator`
#safe

input
- if initial string is empty, returns [’’]

separator

  • if not provided, returns array with input string as only element
  • if empty string, returns array of every character

limit
- ONLY truncates the returned array afterwards

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

substr

A
.substr(num start, num length=length)
=>  {str} substring between start & length
#safe

start

  • if start < 0, start = length+start
  • if start >= length, returns ‘’

length
- if length is

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

substring

A
.substring(num start, num end=length)
=>  {str} substring between start & end index
#safe
#slow - better to use slice()

start|end
- range 0 - length; if outside, converts into closest range member ( end, start & end become swapped

end
- exclusive

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

toLowerCase

A
.toLowerCase()
=>  {str} string lowercased
#safe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

toUpperCase

A
.toUpperCase()
=>  {str} string uppercased
#safe
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

trim

A
.trim()
=>  {str} string with whitespace removed from beginning and end
#ES5
How well did you know this?
1
Not at all
2
3
4
5
Perfectly