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.

  • Escape HTML

    JavaScript, String

    Escapes a string for use in HTML.

  • Extend hex value

    JavaScript, String

    Extends a 3-digit color code to a 6-digit color code.

  • Replaces the last occurrence of a pattern in a string.

  • Unescape HTML

    JavaScript, String

    Unescapes escaped HTML characters.

  • Regular expressions are a very useful tool in a variety of situations. Save this cheatsheet for any time you need to look up their syntax and speed up your development.

  • Copy to clipboard async

    JavaScript, Browser

    Copies a string to the clipboard, returning a promise that resolves when the clipboard's contents have been updated.

  • Swapcase string

    JavaScript, String

    Creates a string with uppercase characters converted to lowercase and vice versa.

  • Titlecase string

    JavaScript, String

    Converts a string to title case.

  • Map string

    JavaScript, String

    Creates a new string with the results of calling a provided function on every character in the given string.

  • Camelcase string

    JavaScript, String

    Converts a string to camelcase.

  • Pascalcase string

    JavaScript, String

    Converts a string to pascal case.

  • Snakecase string

    JavaScript, String

    Converts a string to snake case.

  • Hex to RGB

    JavaScript, String

    Converts a color code to an rgb() or rgba() string if alpha value is provided.

  • String is anagram

    JavaScript, String

    Checks if a string is an anagram of another string (case-insensitive, ignores spaces, punctuation and special characters).

  • String permutations

    JavaScript, String

    Generates all permutations of a string (contains duplicates).