Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
52 views

Javascript Array, String and Regexp Cheat Sheet: by Via

This document provides a cheat sheet on JavaScript array, string, and regular expression methods. It lists and describes methods for creating and manipulating arrays, accessing and modifying array elements, iterating through arrays, and working with strings and regular expressions. These include common methods like push, pop, sort, slice, indexOf, match, replace and more.

Uploaded by

Vlog Info Techno
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Javascript Array, String and Regexp Cheat Sheet: by Via

This document provides a cheat sheet on JavaScript array, string, and regular expression methods. It lists and describes methods for creating and manipulating arrays, accessing and modifying array elements, iterating through arrays, and working with strings and regular expressions. These include common methods like push, pop, sort, slice, indexOf, match, replace and more.

Uploaded by

Vlog Info Techno
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

JavaScript Array, String and RegExp Cheat Sheet

by LeiQ (amethystlei) via cheatography.com/27322/cs/7820/

Create an Array Array instance mutator methods (cont)

By literal way start Index at which to start changing the array. If greater than
[elem​ent0, eleme​nt1, ..., eleme​ntN] the length, will set to length; if negative, will begin from the
new Array(​el​eme​nt0, eleme​nt1[, ...[, eleme​ntN]]) end.

new Array(​ar​ray​Len​gth) dele​‐ If 0, will not delete any element. If Omitted, will be equal to
By using the result of a math teC​‐ length - start
ount
an array is returned by
- RegExp.exec item1, The elements to add to the array
- String.match item2
- String.re​place returns an array containing the deleted elements
By using Methods These methods modify the array
Array.f​​r​o​m​(a​​rra​​yL​ike[, mapFn[, thisArg]])
Array instance Accessor methods
an array-like object (object with a length property and indexed
elements, such as argue​​m​en​​ts) or iterable object (object where concat var new_a​rray = old_a​rra​y.c​on​cat​( v​alu​e1[, value2[, ...
you can get its elements, such as Map and Set). value​N]])

Array.o​f(​el​eme​nt0[, eleme​nt1[, ...[, eleme​ntN]​ ]]) slice var shallo


​ w_c​ opy = arr.s​li​ce(​[b​egin[, end]])

Every argument is considered as an element in the array. begin Zero-b​ased. If negative, indicate an offset from
the end
Array.from and Array.of work like Array constr​uctor to create
join str = arr.j​oi​n([​se​par​ator = ','])
an new array.
indexOf index = arr.i​nd​exO​f(​sea​rch​Ele​ment[, fromI​ndex = 0])
Array instance mutator methods lastIn​‐ index = arr.i​nd​exO​f(​sea​rch​Ele​ment[, fromI​ndex =
copyWi​thi​n( ​tar​get, start[, end = this.l​ength]) dexOf arr.length - 1])

target Target start index


Array instance Iteration methods
start Source start index, if it is negative, treated as length
forEach
+ start
map return new array
fill(​val​ue[, start = 0[, end = this.l​eng​th]])
filter return new array
value Value to fill an array
every return true if every element satisfies testing function
sort([​co​mpa​reF​unc​tion])
some return true if at least one element satisfies testing function
function compare(a, b) {
if (a less than b, or a should be in front of b) {return -1;} find return the found value or undef​ined
if (a is greater than b or be behind of b) {return 1;}
​ return 0; // a must be equal to b
}
splice​(s​tart, delet​eCo​unt[, item1[, item2[, ...]]])

By LeiQ (amethystlei) Published 30th September, 2020. Sponsored by Readable.com


Last updated 30th September, 2020. Measure your website readability!
Page 1 of 3. https://readable.com

cheatography.com/amethystlei/
JavaScript Array, String and RegExp Cheat Sheet
by LeiQ (amethystlei) via cheatography.com/27322/cs/7820/

Array instance Iteration methods (cont) String instance methods unrelated to HTML

findIndex return the found Index or -1 concat str.c​on​cat​( s​tri​ng2, strin​g3[, ..., strin​gN])

callb​ack[, thisArg] repeat str.r​ep​eat​(c​ount)

call​back curr​ent​Value count will convert to integer


'abc'.repeat(2) -> 'abcabc'
index
includes str.​fu​ncN​ame(​ ​sea​rch​Str​ing[, posit​ion])
array
endsWith
reduce accumulate startsWith
reduce​Right accumulate from end sear​chS​‐ A string to be searched for within this
callb​ack[, initi​alV​alue] tring string
call​back prev​iou​sVa​lue posi​tion search from, optional
curr​ent​Value case-s​ens​iti​vity, return true or false
curr​ent​Index
String instance methods related with RegExp
array
entries key/value pairs search str.s​ea​rch​( r​egexp)

keys keys return the index of first match or -1

values values match str.m​at​ch(​re​gexp)


same as regexO
​ bj.​ e​xec​(str)
return an new Array Iterator object
return an array containing the entire match result or null
Some of them can also use for array-like objects by Arra​y.p​rot​oty​‐
result: input, index, 0, 1-n
pe.​fu​n.c​al​l(​arr​ay-like object, args)
replace str.r​ep​lac​e(​reg​exp​ |​sub​str, newSu​bSt​r|​fun
​ ct​ion)
All the Array instance methods regexp pattern

copyWithin fill pop push substr

reverse shift sort splice newSubStr replac​ement


function
unshift concat join slice
newS​ubStr can include some special
toString toLoca​leS​tring indexOf lastIn​dexOf
replac​ement patterns
forEach entries every some
$$ inserts a '$'
filter find findIndex keys
map reduce reduce​Right values

Create a string

String literals
'string text'
"​string text"
String​( t​ext)
`string text ${vari​able}` template strings
Create by Char codes
String.fr​omC​har​Cod​e(​num1[, ...[, numN]])

By LeiQ (amethystlei) Published 30th September, 2020. Sponsored by Readable.com


Last updated 30th September, 2020. Measure your website readability!
Page 2 of 3. https://readable.com

cheatography.com/amethystlei/
JavaScript Array, String and RegExp Cheat Sheet
by LeiQ (amethystlei) via cheatography.com/27322/cs/7820/

String instance methods related with RegExp (cont) Escape notation

$& inserts the matched substring \0 the NULL character


$` inserts the portion of the string that precedes the matched \' single quote
string \" double quote
$' inserts the portion of the string that follows the matched \\ backslash
substring
\n new line
$n or n and nn are decimal digits, inserts the nth parent​hesized
\r carriage return
$nn submatch string
\v vertical tab
func​tio​n's result will be used as the replac​ement, and the
\t tab
arguments is:
\b backspace
match like $&
\f form feed
p1, p2, like $n
... \uXXXX unicode codepoint

offset The offset of the matched substring within the whole string \xXX the Latin-1 character

string the whole string


Create a RegExp

String instance methods related HTML literal notation

anchor str.a​nc​hor​( n​ame) /patt​ern/​ ​flags

create and display an anchor (name property) in a cons​tru​ctor


document new RegExp​(p​att​ern[, flags])
e.g. <a name="n​ame​"​>st​r</​a>
patt​ern The text
link str.l​in​k(​url) flags
create an HTML snippet for a hypertext link g global match
e.g. <a href="u​rl">​str​</a​>
i ignore case
m multiline
All the String instance methods
use test to test for a match in its string parameter.
charAt charCodeAt concat includes

endsWith indexOf lastIn​dexOf locale​‐


Compare
match repeat replace search
slice split startsWith substr
substring toLoca​leL​owe​‐ toLoca​leU​ppe​‐ toLowe​rCase
rCase rCase
toString toUppe​rCase trim valueOf
anchor link

By LeiQ (amethystlei) Published 30th September, 2020. Sponsored by Readable.com


Last updated 30th September, 2020. Measure your website readability!
Page 3 of 3. https://readable.com

cheatography.com/amethystlei/

You might also like