nodejs, find first 100 prime number

Yesterday, when i'm idle and curious, i'm wondering about prime number. Since i'm suck at math, i find it with the suck way. I'm using nodejs because its simple to scripting and cheap on resource. Here is the code :

var stash = [];
for (var i=1; i<100; i++) {
  var tmp = {ke: i, loop: []};
  for (var k=1; k<100; k++) {
    if ((i%k == 0)) {
      tmp.loop.push(k);
    }
  }
  stash.push(tmp);
}

for (var u=0; u<stash.length; u++) {
  if ( stash[u].loop.length == 2 ) {
    console.log(stash[u].ke);
  }
}

Comments