get.js 350 B

1234567891011121314151617181920
  1. /**
  2. * get "nested" object property
  3. */
  4. function get(obj, prop){
  5. var parts = prop.split('.'),
  6. last = parts.pop();
  7. while (prop = parts.shift()) {
  8. obj = obj[prop];
  9. if (typeof obj !== 'object' || !obj) return;
  10. }
  11. return obj[last];
  12. }
  13. module.exports = get;