Ben Brookes
Ben Brookes

Reputation: 439

All Lodash Functions "Not A Function"

I have lodash as part of my sails project. It already existed as part of sails. I have required it in my controller at the top of the file as such..

const lodash = require('lodash');

But no matter what I do, even though autocomplete suggests the function, anything done with them takes the whole app down and produces the "... is not a function" error. It is required fine and sails lifts. I've tried testing with even simple things such as

lodash.foreach([1,2,3], function(a){
    sails.log.debug(a);
});

...and that produces the exact same error.

Upvotes: 0

Views: 1811

Answers (1)

Pritam Banerjee
Pritam Banerjee

Reputation: 18968

You misspelt foreach.

It's forEach like this:

_.forEach([1, 2], function(value) {
  console.log(value);
});
// => Logs `1` then `2`.

_.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).

Upvotes: 5

Related Questions