A Generated Mesh

Consider the following mesh.

It lies in the $xz$ plane, so the $x$ axis points to the right and the $z$ axis points down.

It's a simple $3\times 3$ grid of squares, divided into triangles, connecting a $4\times 4$ grid of vertices.

How might we write JavaScript code to generate the table of vertices and the table of triangles that represent this?

How might we write that code to generate a mesh of arbitrary size?