facebook

Useful JavaScript snippets that you can understand in 30 seconds

Useful JavaScript snippets that you can understand in 30 seconds
Average rating: 3.5
(4 votes)

Thanks! You’ve rated this material!

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:

Adapter

ary
call
collectInto
flip
over
overArgs
pipeAsyncFunctions
pipeFunctions
promisify
rearg
spreadOver
unary

Array

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

Browser

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

Date

dayOfYear
formatDuration
getColonTimeFromDate
getDaysDiffBetweenDates
getMeridiemSuffixOfInteger
isAfterDate
isBeforeDate
isSameDate
maxDate
minDate
tomorrow

Function

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

Math

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

Node

atob
btoa
colorize
hasFlags
hashNode
isDuplexStream
isReadableStream
isStream
isTravisCI
isWritableStream
JSONToFile
readFileLines
untildify
UUIDGeneratorNode

Object

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

String

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

Type

getType
is
isArrayLike
isBoolean
isEmpty
isFunction
isNil
isNull
isNumber
isObject
isObjectLike
isPlainObject
isPrimitive
isPromiseLike
isString
isSymbol
isUndefined
isValidJSON

Utility

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!

Rate this article, if you like it

Thanks! You’ve rated this material!

Got a project? Let's discuss it!

Mailing & Legal Address

Syndicode Inc. 340 S Lemon Ave #3299, Walnut CA, 91789, USA

Visiting & Headquarters address
Kyiv Sofiivska 1/2a, 01001, Kyiv, Ukraine
Dnipro Hlinky 2, of. 1003, 49000, Dnipro, Ukraine
Email info@syndicode.com
Phone (+1) 9035021111