Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

objects.findKey #117

Closed
3 tasks done
jkvyff opened this issue Dec 15, 2019 · 1 comment
Closed
3 tasks done

objects.findKey #117

jkvyff opened this issue Dec 15, 2019 · 1 comment
Labels
enhancement New feature or request operator

Comments

@jkvyff
Copy link
Collaborator

jkvyff commented Dec 15, 2019

FindKey will return the key value of the first object value it encounters that matches or returns true for the predicate

Checklist

  • implementation
  • tests
  • jsdoc

Details

A slight amalgam of version 3 and 4 of Lodash's implementation, with allowing for both array selection notation as well as a 'this' argument.

const users = {
  'barney':  { 'age': 36, 'active': true },
  'fred':    { 'age': 40, 'active': false },
  'pebbles': { 'age': 1,  'active': true }
};
 
Objects.findKey(users, function(chr) {
  return chr.age < 40;
});
// => 'barney' (iteration order is not guaranteed)
 
Objects.findKey(users, { 'age': 1, 'active': true });
// => 'pebbles'
 
Objects.findKey(users, ['active', false]);
// => 'fred'
 
Objects.findKey(users, 'active');
// => 'barney'

References

@evanplaice
Copy link
Member

evanplaice commented Dec 19, 2019

Added in v0.52

@evanplaice evanplaice mentioned this issue Jan 12, 2020
61 tasks
@evanplaice evanplaice changed the title Add objects.findKey objects.findKey Jan 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request operator
Projects
None yet
Development

No branches or pull requests

2 participants