findKey.js 408 B

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