Karthik Mannava
Karthik Mannava

Reputation: 207

Get selected fields from an multiple array object lodash

I have an object like

var data = [
    {
        "inputDate":"2017-11-25T00:00:00.000Z",
        "billingCycle":6,
        "total":1
    },{
        "inputDate":"2017-11-28T00:00:00.000Z",
        "billingCycle":1,"total":1
    }
]

I need to get the result like

var result = [
    {
        "billingCycle":6,
        "total":1
    },{
        "billingCycle":1,
        "total":1
    }
]

tried with

_.map(data, a => _.omit(a, 'inputDate'))

but not I'm not able to achieve the actual result. Please help me on this.

Upvotes: 1

Views: 1658

Answers (1)

Abhyudit Jain
Abhyudit Jain

Reputation: 3748

You have to pass data into the lodash's map function.

_.map(data, a => _.omit(a, 'inputDate'))

The result:

[ { billingCycle: 6, total: 1 }, { billingCycle: 1, total: 1 } ]

Upvotes: 1

Related Questions