findKey.js 406 B

1234567891011121314
  1. var _cb = require('./_cb.js');
  2. var keys = require('./keys.js');
  3. // Returns the first key on an object that passes a truth test.
  4. function findKey(obj, predicate, context) {
  5. predicate = _cb(predicate, context);
  6. var _keys = keys(obj), key;
  7. for (var i = 0, length = _keys.length; i < length; i++) {
  8. key = _keys[i];
  9. if (predicate(obj[key], key, obj)) return key;
  10. }
  11. }
  12. module.exports = findKey;