Loop inside a for loop

Hi,

I have a for loop like below, In which i need to add another radio button which will be a loop according to a user selected value (Which is stored in a variable " i " ). How can i add another loop inside this ? or any other way to do this . Thanks in advance

        for (var NoPrticiField = 1; NoPrticiField <= selectPartiNo; NoPrticiField++) {
            participants.push({
                NoPrticiField: NoPrticiField,
                empname: ko.observable(),
                designation: ko.observable(),
                email: ko.observable()
            });
        }

Eg :

If i = 2

My loop should be like below

<input type=“text” name=“empname” id=“empname”>
<input type=“text” name=“designation” id=“designation”>
<input type=“text” name=“email” id=“email”>
<input type=“radio”> <input type=“radio”>

If you want to use another loop then simply store the loop counter for that loop in a different variable.

Alternatively you could modernise your JavaScript code and get rid of the loops completely by converting the node list to an array and then using one of the modern methods that iterate over the entire array.

ps the loop in the code you posted is using “NoPrticiField” for the loop counter and not “i” as you stated above the code.

Hi felgall,

My loop should be something like below.

for (var NoPrticiField = 1; NoPrticiField <= selectPartiNo; NoPrticiField++) {
participants.push({
NoPrticiField: NoPrticiField,
empname: ko.observable(),
designation: ko.observable(),
email: ko.observable(),

Here i need the new loop

});
}

Hi felgall,

I have code like below, " option: ko.observable() " should be repeated “noOption” times…

        var participants = [];

        for (var NoPrticiField = 1; NoPrticiField &lt;= selectPartiNo; NoPrticiField++) {
          

            fdsfs: for (x = 1; x &lt;= i; x++) {

                noOption = 'Option: ' + x + ''

                alert(noOption);

            };

            participants.push({
                NoPrticiField: NoPrticiField,
                empname: ko.observable(),
                designation: ko.observable(),
                email: ko.observable(),
                option: ko.observable(),
               });
        }