Display a list of java objects online

-3

Good evening.

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 if you only have two fruits look like this: banana, apple, There's a comma at the end. I wanted to avoid this.

    
asked by anonymous 23.05.2018 / 00:26

1 answer

0

Do this:

var frutasEmLinha = ""; 
frutas.forEach(function(fruta, index, array){
    frutasEmLinha += fruta.nome; 
    if(index < array.length - 1){
        frutasEmLinha += ', ';
    } 
});
    
23.05.2018 / 01:39