TypeError: _.pluck is not a function

Hello,

In our collection, we have a script that uses :

_.pluck

When we run the endpoint, we see the following error in console :

Using “_” is deprecated. Use “require(‘lodash’)” instead.

In our scripts, we have added :

const _ = require(‘lodash’);

However, the following error is returned :

TypeError: _.pluck is not a function

Any ideas on how to resolve? Thanks.

Looks like I’ve gotten further following : What Happened to Lodash _.pluck? - GeeksforGeeks

(changing _.pluck to _.map).

Thanks

Hey @mrobbo76 :wave:

Glad to see you found the answer here. :trophy:

Postman was running 2 separate versions of Lodash in the sandbox.

With the _.* entry point it would have been using the the older 3.10.1 version which pluck was part of but with our recent changes we are using the newer version. This doesn’t include that function and show the error.

As you have found out already, the .map() function can be used as a replacement in most cases:

const _ = require('lodash');

let users = [
  { 'user': 'barney' },
  { 'user': 'fred' }
];
 
let userList = _.map(users, 'user');

console.log(userList);
1 Like

Amazing. Thanks for getting back to me, Danny. Keep up the great work :+1:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.