Skip to content

Instantly share code, notes, and snippets.

@ericabell
Created August 29, 2017 03:19
Show Gist options
  • Save ericabell/cf38fb26b09207310529ec2b26613f52 to your computer and use it in GitHub Desktop.
Save ericabell/cf38fb26b09207310529ec2b26613f52 to your computer and use it in GitHub Desktop.
I think the map method runs synchronously
let myBigArray = []
for(let i=0; i<2000000; i++) {
myBigArray.push(i);
}
console.log('Done filling the array.');
let myNewBigArray = myBigArray.map( (e) => {
return e+2;
});
// if map ran *asynchronously* then when we try to console.log the last element
// of myNewBigArray, we would get an error.
console.log(`Last element of myNewBigArray: ${myNewBigArray[myNewBigArray.length-1]}`);
console.log('Done with map');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment