let arrayNomes = new Set()
let novoArray = []
const adicionar = () => {
mercadorias.forEach(mercadoria => {
if (produto === mercadoria.nome) {
let total = item + Number(mercadoria.preco)
setItem(Number(total))
arrayNomes.add(mercadoria.nome)
}
})
novoArray = [...arrayNomes]
setNome(novoArray)
}
I expected it to add a product to the array but without repeating the same item and to show all the items in the array. but it is creating an array for each item added.
New contributor
user22199692 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.