# for of loop that stops at last object of array

I have a for of loop, for each item in the childElements HTMLCollection I want to subtract the height of the elements from the parent height.

let height = element[0].clientHeight;
const childElements = <[HTMLElement]>element[0].children;
let i = 0;
for (const childElement of childElements) {
if (i !== childElements.length - 1) {
height -= Math.ceil(childElement.clientHeight);
}
i++;
}
return height;


But I want to exclude the last HTMLElement in the collection from the for loop. I've now created a i variable that is checked against the length of the collection minus 1. If that's not the case the height of the element is subtracted and i is increased.

This works fine, but it feels like I'm doing two things (for of loop and while loop). Any suggestions?

function returnSuggestedColleaguesWithExpertiseHeight(): number {