Go adding for values in the array

Asked

Viewed 34 times

0

I created an array:

var tagListArray = [];

 for(i = 0; i<resultados.item(i); i++){
    tagListArray = ["valor1", "valor2"];
 }

console.log(tagListArray);

That one resultados.item(i) me returns x values, how do I add to the array?

I did so to test:

var tagListArray = ["Maçã", "Banana"];
                                var data = new Object({data:[]});
                                var index;  

                                for(index = 0; index < results.rows.length; index++) {
                                    alert(results.rows.item(index).descricao);
                                    data.data.push({
                                        tag: tagListArray[index]
                                    });
                                };

But, in tagListArray I want the values to be filled with what the repetition loop returns.

  • resultados.item(i) is an array? What is the structure?

  • @Sam is not an array.

  • You have to see how it is returned to know how to make the loop.

  • results.item(i) has the values a and b. if I give console.log when the is over it returns me ab.

  • You have to inform how this return is, if it is a string, an object... array vc has already said it is not.

  • It’s a string...

  • I really could not understand what you want. Good luck!

Show 2 more comments

1 answer

0

Use the command push() to add a new item in array:

tagListArray.push("String");

If it is an object list you can use it the same way:

tagListArray.push({
  ID: 1,
  Nome: "Valor 1"
});

Browser other questions tagged

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