Lodash: _.findKey for simple value

Created on 16 Apr 2014  路  2Comments  路  Source: lodash/lodash

While _.findKey mimics _.findIndex, it lacks a complement to Array.prototype.indexOf.

Given a single dimensional array:

var states = {
    'AL': 'Alabama',
    'AK': 'Alaska',
    'AZ': 'Arizona',
    'AR': 'Arkansas'
};

I would expect _.findKey(states, 'Alaska') === 'AK', however the _.pluck shorthand is looking for an object with a key of 'Alaska' so the return is undefined;

wontfix

Most helpful comment

Shorthands are consistent in their behavior it would get considerable more complex to make their behavior variable. You may be able to use _.isEqual via
_.findKey(states, _.partial(_.isEqual, 'Alaska'));

All 2 comments

Shorthands are consistent in their behavior it would get considerable more complex to make their behavior variable. You may be able to use _.isEqual via
_.findKey(states, _.partial(_.isEqual, 'Alaska'));

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Alexsey picture Alexsey  路  3Comments

erykpiast picture erykpiast  路  3Comments

andreineculau picture andreineculau  路  3Comments

dengyaolong picture dengyaolong  路  3Comments

jwngr picture jwngr  路  3Comments