Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→object-set-all-values-tonext

object-set-all-values-to6.2.1

Recursively walk the input and set all found values in plain objects to something

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • PURPOSE
  • API — SETALLVALUEST…
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Array primitives stay unchanged
  • Set every value to a custom replacement
  • Set every value to undefined
  • Set the values within nested objects and arrays
  • Each replacement container is a separate object

Purpose

Take any input: nested array, nested plain object or whatever really, no matter how deeply nested. Walk through it recursively and if you find any plain objects, assign all their keys to a given second input’s argument OR default, false.

It does not mutate the input arguments. Operations are done on a cloned input.

We needed this library to overwrite all values to be false on JSON schema objects, so that later when we copy from key/value pairs from schema, values are equal to false and we don’t need to prep them further.

This library is well-tested and is being used in commercial projects.

API — setAllValuesTo()

The main function setAllValuesTo() is imported like this:

It’s a function which takes two input arguments:

Input argumentTypeObligatoryDefaultDescription
input
Type: Plain object
Obligatory: yes
Default: n/a
inputPlain objectyesn/aJSON-like data structure.
value
Type: Any
Obligatory: no
Default: boolean false
valueAnynoboolean falseAssign all the found plain object values to this

The function will return a clone of input with values overwritten (where applicable).

API — version

You can import version:

API — types

This package is written in TypeScript and exports the type Obj — a plain object with string keys and values of any type — what setAllValuesTo() takes and returns.

import type { Obj } from "object-set-all-values-to";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab