<html>
<head>
<title>Texto Area</title>
<script>
var itens = new Array();
var index = 0;
function adicionaItem(item, quantidade)
{
itens[index] = {nomeItem : item, quantidade: quantidade};
index++;
}
function concluirCompra()
{
document.getElementById("nota").innerHTML=getItensToString();
}
function getItensToString()
{
var result = '';
for (i = 0; i < itens.length; i++){
result = result + itens[i]['nomeItem'] + ' ' + itens[i]['quantidade'] + '\r\n';
}
return result;
}
adicionaItem('cafe', 10);
adicionaItem('arroz', 20);
</script>
</head>
<body>
<textarea id="nota" name="nota"></textarea>
<button type=button" onclick="concluirCompra();">Carregar</button>
</body>
</html>
Explanation: Since the variable items is an array of positions, you only have to scan each position to display the data in textarea, with a% wrap of%.
Reference