return object property using lodash from array

前端 未结 4 1252
逝去的感伤
逝去的感伤 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:44

    _.property

    var array = [{a: 1, b: 2}, {a: 3, b: 4}]
    array.map(_.property('a')) // => [1, 3]
    

    _.map short hand

    var array = [{a: 1, b: 2}, {a: 3, b: 4}]
    _.map(array, 'a') // => [1, 3]
    

提交回复
热议问题