How to create a grid in JavaScript?

To create a grid in JavaScript, create a div with display: grid, then add all your cells to it.

So if this is your div:

<div id="my-div"></div>

Then you can create a 3x5 grid in it with this JavaScript:

document.getElementById("my-div").innerHTML = `
  <div style="display: grid; grid-template-columns: repeat(3, 1fr);">

How to change the number of columns?

Change the 3 in repeat(3, 1fr) to change the number of columns.