Get object keys for filtered values

前端 未结 14 1374
傲寒
傲寒 2021-02-05 03:31

The case is simple - I\'ve got a following object:

Object {1: false, 2: true, 3: false, 4: false, 5: false, 6: false, 7: false, 8: true, 12: false, 13: false, 14         


        
14条回答
  •  我在风中等你
    2021-02-05 03:52

    I use this one: Retrieve all keys with the same value from an object (not only an object with just boolean values) using lodash

    function allKeys(obj, value) {
      _.keys(_.pick(obj, function (v, k) { return v === value; }));
    }
    

    Example:

    var o = {a: 3, b: 5, c: 3};
    var desiredKeys = allKeys(o, 3);
    // => [a, c]
    

提交回复
热议问题