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

  • Array to flags object

    Converts an array of strings into an object mapping to true.

    JavaScript, Array · Apr 12, 2022

  • Form to object

    Encodes a set of form elements as an object.

    JavaScript, Browser · Oct 19, 2020

  • Array to object based on key

    Creates an object from an array, using the specified key and excluding it from each value.

    JavaScript, Array · Jun 27, 2021

  • Invert object

    Inverts the key-value pairs of an object, without mutating it.

    JavaScript, Object · Oct 20, 2020

  • Map object keys

    Maps the keys of an object using the provided function, generating a new object.

    JavaScript, Object · Oct 21, 2020

  • Map array to object

    Maps the values of an array to an object using a function.

    JavaScript, Array · Oct 21, 2020

  • Map object values

    Maps the values of an object using the provided function, generating a new object with the same keys.

    JavaScript, Object · Oct 21, 2020

  • Map an array to an object

    Maps an object array to an object, using the provided mapping functions.

    JavaScript, Array · Feb 4, 2023

  • Tip: Pretty-print a JSON object with JavaScript

    Pretty-printing JSON objects in pretty easy and customizable in JavaScript. Here's the gist of it.

    JavaScript, Object · Jul 30, 2022

  • What does 'use strict' do and what are some of the key benefits to using it?

    JavaScript's strict mode can make your code faster, cleaner and more secure.

    JavaScript, Function · Nov 28, 2021

  • Get nested value in object

    Gets the target value in a nested JSON object, based on the given key.

    JavaScript, Object · Oct 19, 2020

  • Get nested value in object based on array of keys

    Gets the target value in a nested JSON object, based on the keys array.

    JavaScript, Object · Oct 19, 2020

  • Value frequencies

    Creates an object with the unique values of an array as keys and their frequencies as the values.

    JavaScript, Array · Oct 19, 2020

  • Nest objects

    Nests recursively objects linked to one another in a flat array.

    JavaScript, Object · Oct 21, 2020

  • Order array of objects

    Sorts an array of objects, ordered by properties and orders.

    JavaScript, Object · Oct 21, 2020