Please see the Wikipedia.
const N = 22; // Vertical
const M = 78; // Horizontal
var a = [], b = [];
a[N/2][M/2] = a[N/2-1][M/2] = a[N/2+1][M/2] = a[N/2][M/2-1] = a[N/2-1][M/2+1] = 1;
function life() {
for (var g = 1; g <= 1000; g++) {
System.print("Generation %4d\n" % g) if (g == 1000);
for (var i = 1; i <= N; i++) {
for (var j = 1; j <= M; j++)
if (a[i][j]) {
System.print("*") if (g == 1000);
b[i-1][j-1]++; b[i-1][j]++; b[i-1][j+1]++;
b[i ][j-1]++; b[i ][j+1]++;
b[i+1][j-1]++; b[i+1][j]++; b[i+1][j+1]++;
} else System.print(".") if (g == 1000);
System.print("\n") if (g == 1000);
}
for (var i = 0; i <= N + 1; i++)
for (var j = 0; j <= M + 1; j++) {
if (b[i][j] != 2) a[i][j] = (b[i][j] == 3);
b[i][j] = 0;
}
}
}
life();
Generation 1000
..............................................................................
.......**.....................................................................
.......**.....................................**..............................
.............................................*..*.............................
............................**................*.*.............................
............................**.................*........**....................
....................................*...................**....................
...........**.......................*.........................................
...........**.......................*.........................................
..............................................................................
...............................**.............................................
..............................*..*............................................
...............................*.*............................................
................................*.............................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................
..............................................................................