lodash sandbox
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
JavaScript
const x = {
validations: {
min: 1,
max: 20,
decimal: {
min: 0,
max: 0
}
}
}
const result = Object.assign(
{},
...function _flatten(o) {
return [].concat(...Object.keys(o)
.map(k =>
typeof o[k] === 'object' ?
_flatten(o[k]) :
({[k]: o[k]})
)
);
}(x)
)
console.log(result)