Last active
February 15, 2022 18:37
-
-
Save filipenevola/12b2d313b04e497bdd6bef5d8489e717 to your computer and use it in GitHub Desktop.
Dúvidas sobre Arrays e Formatação
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Para rodar instale Node.js na sua máquina | |
// E rode pelo terminal com: | |
// node produtos.js | |
const produtos = [ | |
{ | |
nome: "caneta", | |
preco: 2.229, | |
}, | |
{ | |
nome: "feijão", | |
preco: 12, | |
}, | |
{ | |
nome: "arroz", | |
preco: 5, | |
} | |
]; | |
const formatador = new Intl.NumberFormat('pt-BR', { | |
style: 'currency', // moeda | |
currency: 'BRL' | |
}); | |
let totalPreco = 0; | |
for (let i = 0; i < produtos.length; i++) { | |
const produto = produtos[i]; | |
console.log(`${produto.nome}, ${formatador.format(produto.preco)}`); | |
totalPreco += produto.preco; | |
} | |
console.log(`Total: ${formatador.format(totalPreco)}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment