leaves.js 260 B

12345678910111213141516
  1. var Traverse = require('traverse');
  2. var obj = {
  3. a : [1,2,3],
  4. b : 4,
  5. c : [5,6],
  6. d : { e : [7,8], f : 9 },
  7. };
  8. var leaves = Traverse(obj).reduce(function (acc, x) {
  9. if (this.isLeaf) acc.push(x);
  10. return acc;
  11. }, []);
  12. console.dir(leaves);