I am new to lodash and Javascript in general. I am using nodejs. I am using the lodash filter function to filter some contents in my collection.
Here is the snippet
filteredrows = _.filter(rows, function(row, index){
//here I need to call some asynchronous function which checks the row
//the return value of this asynchronous function will determine whether to return true or false for the filter function.
});
My question is, how do I do this? using a closure? Is it possible to do this within the lodash filter function? Thanks in advance.
lodash may not be the best tool for this job. I recommend you use async
.
https://github.com/caolan/async#filter
Example: fs.exists
is an asynchronous function which checks for the existence of a file then calls a callback.
async.filter(['file1','file2','file3'], fs.exists, function(results){
// results now equals an array of the existing files
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With