Skip to content

Instantly share code, notes, and snippets.

@jtn-ms
Last active October 16, 2022 21:51
Show Gist options
  • Save jtn-ms/f93566abb062465ec25e5403fb4a0835 to your computer and use it in GitHub Desktop.
Save jtn-ms/f93566abb062465ec25e5403fb4a0835 to your computer and use it in GitHub Desktop.
cheatsheet for JavaScript
  • String - substring, replace, split, match, includes

  • Array - slice/splice, push/pop, map/filter/forEach, join, sort, some/every/includes/find/findIndex/findLastIndex/indexOf/lastIndexOf,

  • Object - keys, values

  • CSS.selectors - a .a #id

  • CSS.alignment - justify-content, align-items

  • CSS.location - center, space-between, space-around

  • Date Time - Date.now(), Date.parse("..."), new Date("..."), getFullYear(),getUTCDate(),getDay(), getUTCHours(), getTime(), getMinutes(), getSeconds(), getMilliseconds()

  • JSON - JSON.stringify(ob,null,2)

python javascript
json.dumps(ob,indent=2) JSON.stringify(ob,null,2)

Same

python javascript
x[i] x[i]
is.pop(i) is.pop(i)

Different

python javascript
is.append(i) is.push(i)
x[::-1] x.reverse()
str[:9] str.substring(0,9)
x[-1] x.slice(-1)
x[1:5] x.slice(1,5)
is+js [...is,...js]
is+js is.concat(js)
is[:9]+x+is[9:] is.splice(9,0,x)
is[:9]+js+is[9:] is.splice(9,0,...js)
is[9]=x is.splice(9,1,x)
x in y y.includes(x)
any(i>0 for i in is) is.some(i=>i>0)
all(i>0 for i in is) is.every(i=>i>0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment