How to write such a loop?

Please tell me how to write this cycle or how to simplify the function
var size = $(this).find('.catalog-price-size');
var sizeNumb = size.attr("id");
var selectBtn = function (indexBtn) {
 if (width <= 210 && height <= 70) {
 ItemPrice.text(matrix[indexBtn][0] + 'RUB');
}
}
 //This should cycle
 if (sizeNumb == 'size1') {
selectBtn(0);
}
 else if (sizeNumb == 'size2') {
selectBtn(1);
}
 else if (sizeNumb == 'size3') {
selectBtn(2);
}
 else if (sizeNumb == 'size4') {
selectBtn(3);
}
 // and so on
March 19th 20 at 08:31
3 answers
March 19th 20 at 08:33
Solution
const MAX_SIZE = 10; // maximum value

for (let i = 0; i < MAX_SIZE; i++) {
 if (sizeNumb === 'size' + (i + 1)) {
 selectBtn(i); 
break;
}
}
thank you! - ricky commented on March 19th 20 at 08:36
March 19th 20 at 08:35
for (var i = 0; i < 100; i++) {
 var size = 'size' + (i + 1);
 if (sizeNumb == size) {
selectBtn(i);
break;
}
}
thank you! - ricky commented on March 19th 20 at 08:38
March 19th 20 at 08:37
Make sizeX array and checks to do in a loop.

Find more questions by tags jQueryJavaScript