Truth check all values in a JavaScript array
Learn how to check if all values in an array are true or false.
The JavaScript snippet collection contains a wide variety of ES6 helper functions. It includes helpers for dealing with primitives, arrays and objects, as well as algorithms, DOM manipulation functions and Node.js utilities.
Learn how to check if all values in an array are true or false.
Sort an array of numbers, using the bubble sort algorithm.
Quickly and easily check if a string is a yes/no answer to a boolean question in your CLI programs.
Learn how to type check for different types of streams in Node.js.
String splitting and truncation, both simple and locale-sensitive are possible in JavaScript. Learn how in this guide.
Learn how to get the first or last N elements of a JavaScript array, using Array.prototype.slice()
.
Circular JSON objects can't be serialized using JSON.stringify()
, but you can use this trick to handle them.
Injecting CSS into a page via JavaScript is pretty easy, if you know how to leverage the DOM.
Freezing objects is not the only way to prevent mutations. Learn how you can leverage the Proxy object to your advantage.
Learn how to redirect the page to HTTPS if it's currently in HTTP.
Learn how to execute a function for each element of an array, starting from the last one.
Create a debounced function that waits a certain amount of time before invoking the provided function again.
Create a function that ensures another function is called only once.
Have you ever tried appending elements to an array in JavaScript? Here's a primer on all the available options.
Adding a key-value pair to a JavaScript object is straightforward, yet there are multiple ways available to do so.
JavaScript's switch
statement often feels hard to remember and a little bit out of place. Maybe it's time to use object literals, instead.
Get all the partial substrings of a string in JavaScript using generator functions.
JavaScript ES6 introduced us to powerful new features, such as the spread and rest syntax. Learn all you need to know in this quick guide.
Learn how semantic versioning works and how to use it to correctly version your software.
When formatting decimal values in JavaScript, trailing zeros can be undesired. Here's how to deal with them.
Ever wanted to run a function on each animation frame? This snippet shows you how to do it using Window.requestAnimationFrame()
.
JavaScript ES2020 introduced optional chaining and nullish coalescing. Learn everything you need to know with this quick guide.
Quickly find the minimum or maximum date in an array of dates.
Use a regular expression to check if a string contains only alpha or alphanumeric characters in JavaScript.