Display an online java object list

Asked

Viewed 41 times

-3

Good night.

I have a java vector with fruit names

I wanted to display the fruits online : banana, apple, grape presenting on a table. How would you do this using javascript ?

 ${frutas[0].nome },${frutas[1].nome },${frutas[2].nome }

Using this above in case there are only two fruits gets like this: banana, apple, There’s a comma at the end. I wanted to avoid that.

  • 1

    Amanda, rewords your question, explain it better. Are you using "JAVA"? Remember that JAVA has nothing to do with JAVASCRIPT.

1 answer

0

Do it:

var frutasEmLinha = ""; 
frutas.forEach(function(fruta, index, array){
    frutasEmLinha += fruta.nome; 
    if(index < array.length - 1){
        frutasEmLinha += ', ';
    } 
});
  • 2

    I believe that "try" is not a concrete way to solve the problem.

Browser other questions tagged

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