JavaScript Snippets

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.

  • Maps and objects are very similar, but they have some differences that can help you decide which one better fits your use-case.

  • CSV to JSON

    JavaScript, String

    Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.

  • Creates a hash for a value using the SHA-256 algorithm. Returns a promise.

  • JSON to CSV

    JavaScript, Array

    Converts an array of objects to a comma-separated values (CSV) string that contains only the columns specified.

  • Luhn check

    JavaScript, Math

    Implements the Luhn Algorithm, used to validate a variety of identification numbers.

  • 8 tips for accessible websites

    JavaScript, Accessibility

    Accessibility (a11y) can improve your website and attract new users. Learn how to get started with these 8 quick tips.

  • Learn all of the options JavaScript provides for modifying the URL of the current page in the browser without reloading the page.

  • Learn how you can compare two objects in JavaScript using various different techniques.

  • What is a callback function?

    JavaScript, Function

    JavaScript uses callback functions in various places for different purposes. From event listeners to asynchronous operations, they are an invaluable tool you need to master.

  • Compact object

    JavaScript, Object

    Deeply removes all falsy values from an object or array.

  • Heap sort

    JavaScript, Algorithm

    Sorts an array of numbers, using the heapsort algorithm.

  • Query string to object

    JavaScript, Object

    Generates an object from the given query string or URL.

  • Rename object keys

    JavaScript, Object

    Replaces the names of multiple object keys with the values provided.

  • HSL to object

    JavaScript, String

    Converts an hsl() color string to an object with the values of each color.

  • RGB to object

    JavaScript, String

    Converts an rgb() color string to an object with the values of each color.