how to increment a loop javascript object array?

Asked

Viewed 166 times

-1

Good afternoon, I am training my javascript, but I have a question that I could not find a solution on the internet, I want to increment an object array in loop, I found only how to increment array, being object in loop I could not solve, I thank you from now.

var post = {
            teste: 'teste'
        };
        var i = 1;
        while (i <= countOption) {
            option = $('#options'+i).val();
            post.option+i = questionOption;
            i++;
        }
console.log(post)

that’s the code I’m testing

1 answer

1


I’m not on the computer

var post = { test: 'test', option: [] };

And then:

post.option[i] = questionOption;

  • Thanks man, that was good for me, VLW

Browser other questions tagged

You are not signed in. Login or sign up in order to post.