0

I'm using async for NodeJS and iterating over an array as follows:

var async = require('async')

async.forEach(myArray, function (entry, callback) {
  callback(null, entry["value"] + 1)
}, function (error, axResults_p) {
  console.log(arguments)
})

My problem is, that I cannot access the second parameter passed to the callback function. console.log(arguments) shows only one entry. But as far as I know, the first entry is reserved to check for errors.

So, anyone knows what I'm doing wrong/how I can access the results (entry["value"]+1)?

Thanks in advance!

0

1 Answer 1

1

Use async.map, async.parallel instead, each if you want the result from the iterate function.

Sign up to request clarification or add additional context in comments.

4 Comments

Ok, but it seems that I cannot pass an array to async.parallel or async.series as first parameter. It always throws an Exception: TypeError: wrapAsync(...) is not a function when I replace forEach with series or parallel.
try this var async = require('async') async.map(myArray, function (entry, callback) { callback(null, entry["value"] + 1) }, function (error, axResults_p) { console.log(arguments) })
try async.map
asyc.parallel expects a list of functions as the first argument.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.