Skip to content

deleteByPath

Input an object obj and a field path path, then traverse the object deeply according to the path to delete the field at the end of the path.

Added in v0.0.1

Usage

ts
import { deleteByPath } from 'parsnip-kit'

const test0 = { a: 1 }
deleteByPath(test0, 'a') // {}

const test1 = [1]
deleteByPath(test1, '[0]') // []

const test2 = { a: { b: { c: 1 } }, d: [2] }
deleteByPath(test2, 'a.b') // { a: {}, d: [2] }

API

Arguments

ArgTypeOptionalDefaultDescription
objobjectfalseundefinedObject to delete value
pathstringfalseundefinedField path

Returns

Type
void