Skip to content

set

Set a value on an object using a path key

616 bytes

Usage

Opposite of get, dynamically set a nested value into an object using a key path. Does not modify the given initial object.

import * as
import _
_
from 'radashi'
import _
_
.
set<{}, string>(initial: {}, path: string, value: string): {}
export set

Opposite of get, dynamically set a nested value into an object using a key path. Does not modify the given initial object.

@seehttps://radashi.js.org/reference/object/set

@example

set({}, 'name', 'ra') // => { name: 'ra' }
set({}, 'cards[0].value', 2) // => { cards: [{ value: 2 }] }

@version12.1.0

set
({}, 'name', 'ra')
// => { name: 'ra' }
import _
_
.
set<{}, number>(initial: {}, path: string, value: number): {}
export set

Opposite of get, dynamically set a nested value into an object using a key path. Does not modify the given initial object.

@seehttps://radashi.js.org/reference/object/set

@example

set({}, 'name', 'ra') // => { name: 'ra' }
set({}, 'cards[0].value', 2) // => { cards: [{ value: 2 }] }

@version12.1.0

set
({}, 'cards[0].value', 2)
// => { cards: [{ value: 2 }] }