Following content is a example of reponse. It will be deleted from the working page.
Here's a refactored version of the code with an explanation of the changes made:
for (let contour of this.contours) {
const area = cv.contourArea(contour);
const areaRatio = area / srcArea;
}
The size() method is replaced with a for...of loop that
iterates over the this.contours collection directly.
The get() method is removed and the current element is assigned to the
contour variable during each iteration of the loop.