For example:
var array = ['A','B','C','D','E','A','B','C','D','E','A','B','C','D','E'];
function test(cb) {
var newArray = [];
for (var i = 0; i < array.length; i++) {
newArray.push(array[i]);
}
cb(newArray);
}
test(function (data) {
console.log(data);
});
console.log('test');
Let's say that the array has millions of values. It will take long for the newArray to get populated, and meanwhile my other code (console.log) isn't running.
Why isn't it async by default like a lot of things are in JS?
How can I make it more efficient by making it async?