leaves.js 259 B

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