Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Last active May 30, 2021 10:52
Show Gist options
  • Save hoangitk/df1e009467fa3c4fffca11ce9879966b to your computer and use it in GitHub Desktop.
Save hoangitk/df1e009467fa3c4fffca11ce9879966b to your computer and use it in GitHub Desktop.
JS Array methods #js #tutorial
[■,■,■,■].map(■→●) ⇒ [●,●,●,●]
[■,●,■,▲].filter(■→true) ⇒ [■,■]
[■,●,■,▲].find(●→true) ⇒ ●
[■,●,■,▲].findIndex(●→true) ⇒ 1
[■,●,■,▲].fill(●) ⇒ [●,●,●,●]
[■,●,■,▲].some(●→true) ⇒ true
[■,●,■,▲].every(●→true) ⇒ false
[ ].some(●→true) ⇒ false
[ ].every(●→true) ⇒ true
[■,●,[■,▲]].flat() ⇒ [■,●,■,▲]
[■,●].concat([■,▲]) ⇒ [■,●,■,▲]
[■,●,■,▲].join(“-") ⇒ “■-●-■-▲"
[■,●,■,▲].length ⇒ 4
[■,●,▲].keys() ⇒ 0,1,2
[■,●,▲].entries() ⇒ [0,■],[1,●],[2,▲]
[”●”,”■”,”▲"].reduce((a,b)→a+b,“■”) ⇒ "■,●,■,▲”
/*
Credit:
- https://twitter.com/rauschma/status/1398668839177568259
- https://twitter.com/Loilo92/status/1398696994659614722
- https://twitter.com/jibrewery/status/1398801475384623104
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment