return object property using lodash from array

前端 未结 4 1265
逝去的感伤
逝去的感伤 2021-01-31 19:16

I have been trying to return a property of an object by filtering it first. Here\'s what I did:

var characters = [
  { \'name\': \'barney\',  \'age\': 36, \'bloc         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-31 19:33

    _.result(_.find(characters, function(obj) {
           return obj.age === 40;
    }), 'name');
    

提交回复
热议问题