Reputation: 16748
With
const _ = require('lodash');
_.pick({"page":3}, 'page');
I get { page: 3 }
. I just need the value 3
so I have to access varname.page
.
Is there a way to pick from an array and directly return the value/object with lodash?
I just don't like the repetition in here:
let pageNumber = _.pick(params, 'page[number]');
if (!_.isEmpty(pageNumber)) {
pageNumber = parseInt(pageNumber['page[number]']);
}
Upvotes: 0
Views: 448
Reputation: 174957
Uhhh.... I might be missing something obvious but....
const myObj = {"page": 3}
console.log(myObj.page); // 3
//alternatively
console.log(myObj["page"]); // 3
Upvotes: 2