Getting the values for a specific key from all objects in an array

后端 未结 7 1994
醉酒成梦
醉酒成梦 2020-12-15 04:32

I\'m running an express.js app that has a few apis feeding data to dropdown boxes. The data returned is in the form:

  [
    {
        key: \'blah\',
                


        
7条回答
  •  庸人自扰
    2020-12-15 04:57

    In the current versions of Javascript you need a loop do to it.

    However you can use a module like npm `lodash' to make it look simpler

    var _ = require('lodash')
    var permittedValues = _.pluck(array, 'key')
    

    link to pluck documentation

提交回复
热议问题