JavaScript String 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.

  • How do I convert an iterable to an array in JavaScript?

    Learn how to use the JavaScript ES6 spread syntax to converting iterables to arrays and level up your code today.

    JavaScript, Object · Jun 12, 2021

  • URL parameters as object

    Creates an object containing the parameters of the current URL.

    JavaScript, Browser · Oct 22, 2020

  • Format duration

    Returns the human-readable format of the given number of milliseconds.

    JavaScript, Date · Oct 22, 2020

  • Serialize form

    Encodes a set of form elements as a query string.

    JavaScript, Browser · Oct 22, 2020

  • CSV to JSON

    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.

    JavaScript, String · Jan 30, 2022

  • JSON to CSV

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

    JavaScript, Array · Oct 13, 2021

  • Change color lightness

    Changes the lightness value of an hsl() color string.

    JavaScript, String · Oct 31, 2020

  • Common regular expressions

    A collection of regular expressions that can be used to solve common problems.

    JavaScript, String · Nov 9, 2022

  • Parse cookie

    Parses an HTTP Cookie header string, returning an object of all cookie name-value pairs.

    JavaScript, Browser · Oct 22, 2020

  • Copy to clipboard

    Copies a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

    JavaScript, Browser · Jan 11, 2022

  • Index of substrings

    Finds all the indexes of a substring in a given string.

    JavaScript, String · Dec 31, 2020

  • HSL to object

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

    JavaScript, String · Oct 22, 2020

  • RGB to object

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

    JavaScript, String · Oct 22, 2020

  • Caesar cipher

    Encrypts or decrypts a given string using the Caesar cipher.

    JavaScript, Algorithm · Dec 29, 2020

  • Escape HTML

    Escapes a string for use in HTML.

    JavaScript, String · Oct 13, 2021