My top JavaScript utilities, in just One Line of Code!

What's your favorite one-liner in JavaScript?
Here are mine. And if you're a TypeScript fan, you'll be happy to know that most of these snippets work in TypeScript too.

Array

Repeat an array
21 Jul, 2021
Shuffle an array
20 May, 2020
Clone an array
07 May, 2020
Compare two arrays
05 May, 2020
Flatten an array
01 May, 2020
Merge two arrays
19 Apr, 2020
Empty an array
19 Apr, 2020

DOM

Toggle an element
19 Apr, 2020
Show an element
19 Apr, 2020
Replace an element
19 Apr, 2020
Hide an element
19 Apr, 2020

Date Time

Compare two dates
19 Apr, 2020

Function

Box handler
15 Jul, 2020
Memoize a function
16 May, 2020
Uncurry a function
15 May, 2020
Curry a function
15 May, 2020
Identity function
07 May, 2020
Compose functions
07 May, 2020

Math

Misc

Clear all cookies
20 Apr, 2021
Decode a JWT token
23 May, 2020
Encode a URL
03 May, 2020
Detect dark mode
02 May, 2020
Easing functions
25 Apr, 2020
Swap two variables
19 Apr, 2020
Convert hex to rgb
19 Apr, 2020

Number

Subtract arguments
05 May, 2020
Multiply arguments
05 May, 2020

Object

Random

String

Format a string
10 Nov, 2021
Reverse a string
19 Apr, 2020
Repeat a string
19 Apr, 2020

Validator

Recent posts ⚡

Lazy load an image
25 Jan, 2024

Newsletter 🔔

If you're into front-end technologies and you want to see more of the content I'm creating, then you might want to consider subscribing to my newsletter.
By subscribing, you'll be the first to know about new articles, products, and exclusive promotions.
Don't worry, I won't spam you. And if you ever change your mind, you can unsubscribe at any time.
Phước Nguyễn