safe-flat
Safely flatten a nested JavaScript object.
Installation
$ npm i safe-flat
Methods
flatten(obj, [delimiter])
Flats an object to one level deep. Optionally takes a custom delimiter
, otherwise uses .
by default. Circular references within the object will be replaced with [Circular]
.
const flatten = require('safe-flat')
const original = {
a: {
b: {
c: [{
val: 'one'
}, {
val: 'two'
}],
d: 'three'
},
e: 'four',
}
}
original.a.b.f = original.a.b
original.a.b.c.push(original.a)
const flat = flatten(original)
const underscoreFlat = flatten(original, '_')