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.

  • Checks if a number has any decimals digits

  • Head of array

    JavaScript, Array

    Returns the head of an array.

  • Value is object

    JavaScript, Type

    Checks if the passed value is an object or not.

  • Value is object-like

    JavaScript, Type

    Checks if a value is object-like.

  • Value is plain object

    JavaScript, Type

    Checks if the provided value is an object created by the Object constructor.

  • Number is primitive

    JavaScript, Type

    Checks if the passed value is primitive or not.

  • Same-origin URLs

    JavaScript, Object

    Checks if two URLs are on the same origin.

  • Value is string

    JavaScript, Type

    Checks if the given argument is a string. Only works for string primitives.

  • Pad number

    JavaScript, String

    Pads a given number to the specified length.

  • Rounds a number to a specified amount of digits.

  • Array union

    JavaScript, Array

    Returns every element that exists in any of the two arrays at least once.

  • Validate number

    JavaScript, Math

    Checks if the given value is a number.

  • Binary function arity

    JavaScript, Function

    Creates a function that accepts up to two arguments, ignoring any additional arguments.

  • Clamp number

    JavaScript, Math

    Clamps num within the inclusive range specified by the boundary values a and b.

  • Clone RegExp

    JavaScript, Type

    Clones a regular expression.