JavaScript array filtering tips
A few tips and tricks to help you filter arrays in JavaScript more efficiently.
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.
A few tips and tricks to help you filter arrays in JavaScript more efficiently.
Efficiently check if a numeric array is sorted in ascending or descending order in JavaScript.
Explore how you can apply mathematical set operations to JavaScript Set
objects and arrays.
Easily create a debounced function that returns a promise.
Use JavaScript's Math.hypot()
to calculate the Euclidean distance between two points.
Learn how to retrieve and manipulate the styles of an HTML element easily and efficiently with JavaScript.
Learn how to create an inclusive array with numbers in a range, using a common step
difference.
Given a sorted array, find the correct index to insert a given value.
Inverts the key-value pairs of an object, without mutating it.
Learn how to check if a number is prime and how to generate prime numbers up to a given number in JavaScript.
Learn how to leverage Intl.ListFormat
to join an array into a string, with appropriate separators.
Have you ever wanted to serialize an object but only include certain keys? Turns out JavaScript provides an easy way to do this!
Arrays are one of the most used data types in any programming language. Learn how to merge two arrays in JavaScript with this short guide.
Sort an array of numbers, using the merge sort algorithm.
Create an array of partial sums, using Array.prototype.reduce()
and Array.prototype.slice()
.
Trailing commas are not without controversy. Here's why I think you should use them.
Learn how to create a unit converter data structure in JavaScript that can convert between any compatible units.
Learn how to check if an array has one or more values matching the given function, and how to find the matching elements.
Understand why JavaScript's built-in array sorting is not stable and how to implement a stable sorting algorithm.
A stack is a linear data structure which follows a last in, first out (LIFO) order of operations.
Using the Proxy object, we can create chainable dynamic getters for objects in JavaScript.
Learn how to create a frozen Set
or Map
in JavaScript.
Create a generator function that finds all the indexes of a substring in a given string.
Iterate over all own properties of an object, running a callback for each one.