findKey.js 386 B

12345678910111213
  1. import cb from './_cb.js';
  2. import keys from './keys.js';
  3. // Returns the first key on an object that passes a truth test.
  4. export default 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. }