Get item from an array with jQuery

Asked

Viewed 643 times

0

I have the following structure:

[{tabela: 'tabela1', coluna: 'coluna1'}, {tabela: 'tabela2', coluna: 'coluna2'}]

I need to insert this data into a div in format:

[TABLE.COLUMN]

In case it would:

[Tabela1.coluna1] [table2.coluna2]

But I’m not finding a solution to this with jQuery. How could I do that ?

  • "Get item from an array with jQuery", no need even jQuery: object...[...], this is the same as indexing an object with the ., but computably. There are several ways to traverse an array, among them the best is to memorize its size and increment a temporary index to a certain limit. You can also scroll through the array directly like this: for (var i = 0, item; (item = array[i++]) !== undefined;), a loop that breaks until an item arrives undefined.

  • In your case you would only need to go through the items of your Array

1 answer

3


Hello friend I hope I can help in the doubt

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  var json = [
                 { tabela: 'tabela1', coluna: 'coluna1'},
                 {tabela: 'tabela2', coluna: 'coluna2'}
             ];

    $.each(json,function (index, value) { 
       $('#conteudo').append('index =' + index + ' - ' + value.tabela +' - ' + value.coluna + '</br>');
    });  

});
</script>
<div id="conteudo"></div>

Browser other questions tagged

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