-
Notifications
You must be signed in to change notification settings - Fork 3
flat
Subhajit Sahu edited this page Jun 11, 2020
·
13 revisions
Flattens nested object to given depth. 🏃 [:vhs:] 📦 🌔 📒
object.flat(x, [dep]);
// x: a nested object
// dep: maximum depth (-1)const object = require('extra-object');
var x = {ab: {a: 1, b: 2}, cde: {c: 3, de: {d: 4, e: {e: 5}}}};
object.flat(x);
// { a: 1, b: 2, c: 3, d: 4, e: 5 }
object.flat(x, 1);
// { a: 1, b: 2, c: 3, de: { d: 4, e: { e: 5 } } }
object.flat(x, 2);
// { a: 1, b: 2, c: 3, d: 4, e: { e: 5 } }