We used to share with you our rare findings. Today we have something special – the currated list of useful JavaScript snippets that you can understand in 30 seconds or less. From Adapter to Utility. Enjoy!
As a short intro, we remind you that ‘snippet’ is a programming term for a small region of re-usable source code, machine code, or text. This is the operative units to incorporate into larger programming modules. In JS there are many neat snippets you could probably know by now. But this time we aim to show some of them that are quite simple to understand in a short timeframe and immediately start using.
This is the list of useful JavaScript snippets that are written in ES6. You should use the Babel transpiler to ensure backwards-compatibility.
In this collection you will find the next bunch of JS snippets:
ary
call
collectInto
flip
over
overArgs
pipeAsyncFunctions
pipeFunctions
promisify
rearg
spreadOver
unary
all
allEqual
any
arrayToCSV
bifurcate
bifurcateBy
chunk
compact
countBy
countOccurrences
deepFlatten
difference
differenceBy
differenceWith
drop
dropRight
dropRightWhile
dropWhile
everyNth
filterNonUnique
filterNonUniqueBy
findLast
findLastIndex
flatten
forEachRight
groupBy
head
indexOfAll
initial
initialize2DArray
initializeArrayWithRange
initializeArrayWithRangeRight
initializeArrayWithValues
initializeNDArray
intersection
intersectionBy
intersectionWith
isSorted
join
JSONtoCSV
last
longestItem
mapObject
maxN
minN
none
nthElement
offset
partition
permutations
pull
pullAtIndex
pullAtValue
pullBy
reducedFilter
reduceSuccessive
reduceWhich
reject
remove
sample
sampleSize
shank
shuffle
similarity
sortedIndex
sortedIndexBy
sortedLastIndex
sortedLastIndexBy
stableSort
symmetricDifference
symmetricDifferenceBy
symmetricDifferenceWith
tail
take
takeRight
takeRightWhile
takeWhile
toHash
union
unionBy
unionWith
uniqueElements
uniqueElementsBy
uniqueElementsByRight
uniqueSymmetricDifference
unzip
unzipWith
without
xProd
zip
zipObject
zipWith
arrayToHtmlList
bottomVisible
copyToClipboard
counter
createElement
createEventHub
currentURL
detectDeviceType
elementContains
elementIsVisibleInViewport
getImages
getScrollPosition
getStyle
hasClass
hashBrowser
hide
httpsRedirect
insertAfter
insertBefore
isBrowserTabFocused
nodeListToArray
observeMutations
off
on
onUserInputChange
prefix
recordAnimationFrames
redirect
runAsync
scrollToTop
setStyle
show
smoothScroll
toggleClass
triggerEvent
UUIDGeneratorBrowser
dayOfYear
formatDuration
getColonTimeFromDate
getDaysDiffBetweenDates
getMeridiemSuffixOfInteger
isAfterDate
isBeforeDate
isSameDate
maxDate
minDate
tomorrow
attempt
bind
bindKey
chainAsync
compose
composeRight
converge
curry
debounce
defer
delay
functionName
hz
memoize
negate
once
partial
partialRight
runPromisesInSeries
sleep
throttle
times
uncurry
unfold
when
approximatelyEqual
average
averageBy
binomialCoefficient
clampNumber
degreesToRads
digitize
distance
elo
factorial
fibonacci
gcd
geometricProgression
hammingDistance
inRange
isDivisible
isEven
isPrime
lcm
luhnCheck
maxBy
median
minBy
percentile
powerset
primes
radsToDegrees
randomIntArrayInRange
randomIntegerInRange
randomNumberInRange
round
sdbm
standardDeviation
sum
sumBy
sumPower
toSafeInteger
atob
btoa
colorize
hasFlags
hashNode
isDuplexStream
isReadableStream
isStream
isTravisCI
isWritableStream
JSONToFile
readFileLines
untildify
UUIDGeneratorNode
bindAll
deepClone
deepFreeze
defaults
dig
equals
findKey
findLastKey
flattenObject
forOwn
forOwnRight
functions
get
invertKeyValues
lowercaseKeys
mapKeys
mapValues
matches
matchesWith
merge
nest
objectFromPairs
objectToPairs
omit
omitBy
orderBy
pick
pickBy
renameKeys
shallowClone
size
transform
truthCheckCollection
unflattenObject
byteSize
capitalize
capitalizeEveryWord
CSVToArray
CSVToJSON
decapitalize
escapeHTML
escapeRegExp
fromCamelCase
indentString
isAbsoluteURL
isAnagram
isLowerCase
isUpperCase
mapString
mask
pad
palindrome
pluralize
removeNonASCII
reverseString
sortCharactersInString
splitLines
stringPermutations
stripHTMLTags
toCamelCase
toKebabCase
toSnakeCase
toTitleCase
truncateString
unescapeHTML
URLJoin
words
getType
is
isArrayLike
isBoolean
isEmpty
isFunction
isNil
isNull
isNumber
isObject
isObjectLike
isPlainObject
isPrimitive
isPromiseLike
isString
isSymbol
isUndefined
isValidJSON
View contents
castArray
cloneRegExp
coalesce
coalesceFactory
extendHex
getURLParameters
hexToRGB
httpGet
httpPost
isBrowser
mostPerformant
nthArg
parseCookie
prettyBytes
randomHexColorCode
RGBToHex
serializeCookie
timeTaken
toCurrency
toDecimalMark
toOrdinalSuffix
validateNumber
yesNo
You can find here any snippets you need! Read the details and explore all of these JS snippets in details on GitHub.
Also, find great open source repositories and interesting solutions on our JS Digest!