3👍
You can use getElementsByClassName to retrieve all the box divs and get the array length:
var columns = document.getElementsByClassName('box').length
1👍
I think you are missing the minmax part of the grid-template-columns:
eg grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
with out it, you will always have 7 columns, and the grid columns wont be responsive and change as page width shrinks/expands.
can see Jen Simmons example page here : Spice Gallery Layout
A Solution that doesnt require any javascript.. but a few media queries..
is to wrap your .wrapper div with a container. and set a max height. per screen break point when every there would be un even images on the last row.
then set the .container overflow-y:hidden;
link to pen here : Hide last row of grid with css
Doing this with javascript you would need to know how many images you have, and what your minmax column widths are. vw units are basicaly width in %. so you would need to do some maths. with a mod function to know how many items are on the last row. and then need a way to hide them.