Is Node.js Array.map() asynchronous?

Can I count on nodeIDs mapping is completed every time doSomething() is called?

nodeIDs = $.map(nodeIDs, function(n){
    return n.match(/\d+$/);
});
doSomething(nodeIDs);

I thought all callbacks in node.js are asynchronous? I did read an article on general programming that callback could be synchronous but I am not sure about node.js?

JavaScript is also a functional programming language. What you have here is a «higher order function», a function which takes a function as a parameter. Higher order functions are synchronous.

Sources:

map() is a typical example of a higher order function. It takes a function and applies it to all elements of an array. The definition sounds very «functional». This function is also not provided by Node. It is documented by MDN Array.prototype.map() and specified by ECMAScript 5.1.

To answer your question: Yes, doSomething(nodeIDs) is called after all elements have been applied.

Yes, .map is synchronous. "Callback" does not imply "asynchronous".

This function is synchronous - otherwise it couldn't return the result of the map operation.

Any callbacks that might take longer time (mainly due to IO) are asynchronous in nodejs - unless the method is explicitely marked as being synchronous (such as fs.readFileSync - but that doesn't use a callback). You probably confused that somehow.

import the async module to have an asynchronous 'map' method

var async = require('async');

var arr = ['1','2'];
async.map(arr, getInfo, function (e, r) {
  console.log(r);
});

function getInfo(name, callback) {
  setTimeout(function() {
    callback(null, name + 'new');
  }, 1000);
}

example here: http://runnable.com/UyR-6c2DZZ4SmfSh/async-map-example-for-node-js